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

Functions

Returns a Stream of file paths discovered by walking through directories underneath the starting path provided.

Link to this section Functions

Link to this function

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 return true if the directory should be skipped, or false if the directory should be traversed. Defaults to nil.

  • sort: sorts the files inside a directory before returning them. Defaults to true.

  • include_stat: instead of returning a String 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 to false.

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"))