crabwalk is a Python package built in Rust on top of the excellent ignore crate:
The ignore crate provides a fast recursive directory iterator that respects various filters such as globs, file types and .gitignore files.
By default, Walk
will recursively traverse the given path(s) while ignoring
hidden files and those matching globs found in .gitignore
and .ignore
files:
from crabwalk import Walk
with Walk(".") as walk:
for entry in walk:
print(entry.path)
To disable all default filtering (and therefore behave more like os.walk
),
you can set the corresponding flags individually or use the helper method shown
here:
from crabwalk import Walk
with Walk(".") as walk:
walk.disable_standard_filters()
for entry in walk:
print(entry.path)
Disable the hidden files filter and enable parsing of custom ignore files called
.myignore
:
from crabwalk import Walk
with Walk(".", hidden=False, custom_ignore_filenames=(".myignore",)) as walk:
for entry in walk:
print(entry.path)
See the documentation for all options.