Thanks to visit codestin.com
Credit goes to lib.rs

9 releases

new 0.2.2 Jan 14, 2026
0.2.1 Jan 14, 2026
0.2.0 Sep 26, 2025
0.1.5 Apr 30, 2025
0.1.0 Sep 4, 2024

#400 in Filesystem

Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App Codestin Search App

548 downloads per month
Used in 4 crates (3 directly)

GPL-3.0 license

35KB
499 lines

GitHub Actions Workflow Status Crates.io Version docs.rs

fs_walk is a Rust crate for efficiently and flexibly walking the filesystem. It provides a simple, ergonomic API for recursively traversing directories with fine-grained control over filtering, sorting, and symlink handling.

Why Use fs_walk?

  • Flexible filtering: Filter by file extension, name, regex, or custom predicates.
  • Batch processing: Process files in chunks for memory efficiency.
  • Symlink handling: Safely follow symlinks with loop protection.
  • Ergonomic API: Chainable methods for intuitive configuration.

Features

Feature Description
Depth control Limit traversal depth to avoid unnecessary work.
Result chunking Process results in batches for memory efficiency.
Filtering Filter by extension, name, regex, or custom predicates.
Symlink support Optionally follow symlinks with loop protection.
Sorting Sort directory entries for consistent results.
Regex matching Enable regex-based filtering (requires the regex feature).

Installation

Add fs_walk to your Cargo.toml:

[dependencies]
fs_walk = "0.2"

Cargo Features

  • regex: Enables regex matching for file and directory names, using the regex crate Enable with:
    [dependencies]
    fs_walk = { version = "0.2", features = ["regex"] }
    

Usage

Basic Usage

Walk all files and directories in the current directory:

use fs_walk::WalkOptions;

let walker = WalkOptions::new().walk(".");
for path in walker.flatten() {
    println!("Found: {:?}", path);
}

Filtering Files

Walk only Rust files (.rs extension):

use fs_walk::WalkOptions;

let walker = WalkOptions::new()
    .files()
    .extension("rs")
    .walk(".");
for path in walker.flatten() {
    println!("Found Rust file: {:?}", path);
}

Chunking Results

Process files in chunks of 10 for batch operations:

use fs_walk::WalkOptions;

let walker = WalkOptions::new()
    .files()
    .extension("o")
    .walk(".")
    .chunks(10);
for chunk in walker {
    for path in chunk.iter().flatten() {
        println!("Processing: {:?}", path);
    }
}

Regex Matching

Walk files matching a regex pattern (requires the regex feature):

use fs_walk::WalkOptions;

let walker = WalkOptions::new()
    .name_regex(r#"^.*\.rs$"#)
    .unwrap()
    .walk(".");
for path in walker.flatten() {
    println!("Found matching file: {:?}", path);
}

Walk directories while following symlinks (with loop protection):

use fs_walk::WalkOptions;

let walker = WalkOptions::new()
    .dirs()
    .follow_symlink()
    .walk(".");
for path in walker.flatten() {
    println!("Found directory: {:?}", path);
}

Contributing

Contributions are welcome! If you’d like to report a bug, suggest a feature, or submit a PR.

License

This project is licensed under the GPL-3 License.

Dependencies

~1.5–2.3MB
~52K SLoC