I needed to write some path filtering code today, (and I remembered some of the stuff we did in PutPlace) so I knocked together pathfinder.
I didn’t spend any time worrying about the API design and naming, so I’m sure there’s a bunch of enhancements that could be made. If you have any suggestions, leave some feedback here.
Here are some examples of it in action:
import pathfinder
# get all directories and sub-directories in current directory
paths = pathfinder.pathfind(".", just_dirs=True)
# get all files in the current directory and all sub-directories
paths = pathfinder.pathfind(".", just_files=True)
# get all jpg files using a regex
paths = pathfinder.pathfind(".", regex=".*\.jpg$")
# get all jpg files using posix wildcards
paths = pathfinder.pathfind(".", fnmatch="*.jpg")
# get all jpg files and png files
jpg_filter = pathfinder.FnmatchFilter("*.jpg")
png_filter = pathfinder.FnmatchFilter("*.png")
image_filter = pathfinder.OrFilter(jpg_filter, png_filter)
paths = pathfinder.pathfind(".", filter=image_filter)