A cross platform Rust library for efficiently walking a directory recursively. Comes with support for following symbolic links, controlling the number of open file descriptors and efficient mechanisms for pruning the entries in the directory tree.
Dual-licensed under MIT or the UNLICENSE.
To use this crate, add
walkdir as a dependency to your project's
The following code recursively iterates over the directory given and prints the path for each entry:
Or, if you'd like to iterate over all entries and ignore any errors that may
filter_map. (e.g., This code below will silently skip directories
that the owner of the running process does not have permission to access.)
Example: follow symbolic links
The same code as above, except
follow_links is enabled:
Example: skip hidden files and directories efficiently on unix
This uses the
filter_entry iterator adapter to avoid yielding hidden files
and directories efficiently:
Minimum Rust version policy
This crate's minimum supported
rustc version is
The current policy is that the minimum Rust version required to use this crate
can be increased in minor version updates. For example, if
crate 1.0 requires
Rust 1.20.0, then
crate 1.0.z for all values of
z will also require Rust
1.20.0 or newer. However,
crate 1.y for
y > 0 may require a newer minimum
version of Rust.
In general, this crate will be conservative with respect to the minimum supported version of Rust.
The short story is that performance is comparable with
find and glibc's
nftw on both a warm and cold file cache. In fact, I cannot observe any
performance difference after running
walkdir / and
nftw / on my
local file system (SSD, ~3 million entries). More precisely, I am reasonably
confident that this crate makes as few system calls and close to as few
allocations as possible.
I haven't recorded any benchmarks, but here are some things you can try with a
local checkout of
On my system, the performance of
nftw is comparable.