Skip to content

walk

Every file below dir, at any depth, sorted by path.

Directories themselves are not listed (an empty one contributes nothing), and symbolic links are listed as entries but not followed, so a link to a parent directory cannot make the walk loop.

use helpers4::fs::walk;

Cargo feature fs (enabled by default). To compile only this module:

cargo add helpers4 --no-default-features --features fs

or in Cargo.toml:

[dependencies]
helpers4 = { version = "0.0.6", default-features = false, features = ["fs"] }
pub fn walk(dir: impl AsRef<Path>) -> io::Result<Vec<PathBuf>>
ParameterTypeDescription
dirimpl AsRef<Path>The directory to walk.

io::Result<Vec<PathBuf>>

An io::Error when dir, or a directory below it, cannot be read.

use helpers4::fs::{walk, write_atomic};

let root = std::env::temp_dir().join("helpers4-walk-doc");
std::fs::create_dir_all(root.join("sub"))?;
write_atomic(root.join("a.txt"), "a")?;
write_atomic(root.join("sub").join("b.txt"), "b")?;
assert_eq!(walk(&root)?, vec![root.join("a.txt"), root.join("sub").join("b.txt")]);

src/fs/walk.rs