Crate globwalk

Recursively find files in a directory using globs.

Features include

Examples

Finding image files in the current directory.

extern crate globwalk;
# include!("doctests.rs");

use std::fs;
# fn run() -> Result<(), Box<dyn ::std::error::Error>> {
# let temp_dir = create_files(&["cow.jog", "cat.gif"])?;
# ::std::env::set_current_dir(&temp_dir)?;

for img in globwalk::glob("*.{png,jpg,gif}")? {
    if let Ok(img) = img {
        fs::remove_file(img.path())?;
    }
}
# Ok(()) }
# fn main() { run().unwrap() }

Advanced Globbing

By using one of the constructors of globwalk::GlobWalker, it is possible to alter the base-directory or add multiple patterns.

extern crate globwalk;
# include!("doctests.rs");

use std::fs;

# fn run() -> Result<(), Box<dyn ::std::error::Error>> {
# let temp_dir = create_files(&["cow.jog", "cat.gif"])?;
# let BASE_DIR = &temp_dir;
let walker = globwalk::GlobWalkerBuilder::from_patterns(
        BASE_DIR,
        &["*.{png,jpg,gif}", "!Pictures/*"],
    )
    .max_depth(4)
    .follow_links(true)
    .build()?
    .into_iter()
    .filter_map(Result::ok);

for img in walker {
    fs::remove_file(img.path())?;
}
# Ok(()) }
# fn main() { run().unwrap() }

Structs

Functions

Type Aliases