Skip to content

dannywoodz/efind

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

efind

Copyright (c) 2016 Danny Woods

Version: 2.0

Authors: Danny Woods ([email protected]).

efind is a utility library in the spirit of the Unix find tool

Examples

efind:find/1 and efind:find/2 scan the selected root and return a list of results.

  RootDir = "...".
  ListOfTuples = efind:find(RootDir). % Each tuple is {file, Filename} or {dir, Dirname}
  ListOfNames = efind:find(RootDir, [{result_type,names}]).
  ListOfFileNames = efind:find(RootDir, [{result_type,names},{dirs,false}]).
  ListOfDirNames = efind:find(RootDir, [{result_type,names},{files,false}]).
  ListOfXmlFiles = efind:find(RootDir,
  		 [{result_type,names},
		 {dirs,false},
		 {accept_fn, fun(Name) -> filename:extension(Name) == ".xml" end}]).

efind:scan/1 and efind:scan/2 are lazy versions of find. In concert with efind:next/1, they can be used to walk the filesystem on-demand. A scanner that is drained of all content will return finished from efind:next/1 and is terminated automatically. However, if you wish to abandon scanning early, you must call efind:close/1 to release the scanner. You'll leak a process per invocation otherwise.

  RootDir = "...".
  Scanner = efind:scan(RootDir),
  Fn = fun(finished, _F) ->
	  	io:format("Done~n"),
	  (Entry, F) ->
	  	io:format("~p~n", [Entry]),
		F(efind:next(Scanner), F)
	end,
  Fn(efind:next(Scanner), Fn).

Modules

efind

About

A find-like utility library for Erlang

Resources

License

Stars

Watchers

Forks

Packages

No packages published