TreeWalker (tree_walker v0.2.0)
TreeWalker provides a Stream
style interface for recursively walking through
directories and returning the file paths discovered.
Link to this section Summary
Link to this section Functions
stream(path, opts \\ [])
Returns a Stream
of file paths discovered by walking through directories
underneath the starting path
provided.
Accepts some options:
skip_dir
: if provided, must be a function with a single argument, returning a boolean. This will be called with every directory discovered. The function will be passed the path of the directory, and must returntrue
if the directory should be skipped, orfalse
if the directory should be traversed. Defaults tonil
.sort
: sorts the files inside a directory before returning them. Defaults totrue
.include_stat
: instead of returning aString
for each path, returns a tuple of the{path, %File.Stat{}}
. This is handy if you want to check for file sizes or permissions in a later stage, but can increase memory usage. Defaults tofalse
.
Tips
If you want to filter the files returned, use a subsequent Stream.filter/2
or Stream.reject/2
operation, such as:
TreeWalker.stream(path)
|> Stream.reject(&String.ends_with?(&1, ".json"))