Home

Do A Glob Search For Files In A Directory With Rust

Basic Recursive Glob

rust
//! ```cargo
//! [dependencies]
//! glob = "0.3.1"
//! ```


use glob::glob;

fn main() {
    for entry in glob("recursive_test/**/*.txt").expect("Failed to read glob pattern") {
        match entry {
            Ok(path) => println!("{:?}", path.display()),
            Err(e) => println!("{:?}", e),
        }
    }
}
results start
Note

The code uses the [TODO: Code shorthand span ] and [TODO: Code shorthand span ] crates which can be installed with:

[TODO: Code shorthand span ] [TODO: Code shorthand span ]

~ fin ~

References

  • An alternative method for processing all the files and diretories directly instead of via the glob filtered set.