walkthrough
A recursive directory iterator for Rust with depth control, symlink loop detection, sorting, and hidden-file filtering.
Usage
use WalkDir;
for entry in new.min_depth.max_depth.skip_hidden
Configuration
| Method | Default | Description |
|---|---|---|
min_depth(n) |
0 |
Skip entries shallower than n |
max_depth(n) |
unlimited | Skip entries deeper than n |
follow_links(bool) |
false |
Follow symbolic links |
skip_hidden(bool) |
false |
Omit dot-files and dot-directories |
group_dir(bool) |
false |
Yield directories before files at each level |
sort_by(fn) |
none | Custom comparator for entries within a directory |
Sorting example
use WalkDir;
let walker = new
.group_dir
.sort_by;
How it works
The walker maintains a stack of open directory iterators. Each directory is read, optionally sorted, and pushed onto the stack. On backtracking the stack is popped, keeping memory proportional to the depth of the tree rather than its total size.
Symlink loop detection compares device/inode identifiers (or equivalent) of every ancestor in the current path. A loop is reported as an error and traversal continues.
Development
just is used to run common tasks:
just fmt # check formatting
just clippy # run linter
just test # run all tests
just ci # full CI suite
Roadmap
- Async support (
tokio/async-std)
License
Licensed under either of Apache License, Version 2.0 or MIT license at your option.