#glob #patterns #shell #unix #file

glob

Support for matching file paths against Unix shell style patterns

26 releases

0.3.0 Mar 7, 2019
0.2.11 Mar 6, 2016
0.2.10 Apr 14, 2015
0.2.7 Mar 25, 2015
0.1.0 Nov 27, 2014

#10 in Filesystem

Download history 61702/week @ 2019-07-30 62397/week @ 2019-08-06 62325/week @ 2019-08-13 61544/week @ 2019-08-20 59831/week @ 2019-08-27 65966/week @ 2019-09-03 63744/week @ 2019-09-10 70247/week @ 2019-09-17 73717/week @ 2019-09-24 74535/week @ 2019-10-01 76756/week @ 2019-10-08 78802/week @ 2019-10-15 84401/week @ 2019-10-22 80634/week @ 2019-10-29 87495/week @ 2019-11-05

158,345 downloads per month
Used in 1,959 crates (317 directly)

MIT/Apache

52KB
961 lines

glob

Support for matching file paths against Unix shell style patterns.

Build Status

Documentation

Usage

To use glob, add this to your Cargo.toml:

[dependencies]
glob = "0.3.0"

And add this to your crate root:

extern crate glob;

Examples

Print all jpg files in /media/ and all of its subdirectories.

use glob::glob;

for entry in glob("/media/**/*.jpg").expect("Failed to read glob pattern") {
    match entry {
        Ok(path) => println!("{:?}", path.display()),
        Err(e) => println!("{:?}", e),
    }
}

lib.rs:

Support for matching file paths against Unix shell style patterns.

The glob and glob_with functions allow querying the filesystem for all files that match a particular pattern (similar to the libc glob function). The methods on the Pattern type provide functionality for checking if individual paths match a particular pattern (similar to the libc fnmatch function).

For consistency across platforms, and for Windows support, this module is implemented entirely in Rust rather than deferring to the libc glob/fnmatch functions.

Examples

To print all jpg files in /media/ and all of its subdirectories.

use glob::glob;

for entry in glob("/media/**/*.jpg").expect("Failed to read glob pattern") {
    match entry {
        Ok(path) => println!("{:?}", path.display()),
        Err(e) => println!("{:?}", e),
    }
}

To print all files containing the letter "a", case insensitive, in a local directory relative to the current working directory. This ignores errors instead of printing them.

use glob::glob_with;
use glob::MatchOptions;

let options = MatchOptions {
    case_sensitive: false,
    require_literal_separator: false,
    require_literal_leading_dot: false,
};
for entry in glob_with("local/*a*", options).unwrap() {
    if let Ok(path) = entry {
        println!("{:?}", path.display())
    }
}

No runtime deps