27 releases

Uses old Rust 2015

0.3.1 Jan 6, 2023
0.3.0 Mar 7, 2019
0.2.11 Mar 6, 2016
0.2.10 Apr 14, 2015
0.1.0 Nov 27, 2014

#4 in Filesystem

Download history 1030145/week @ 2024-01-10 1158943/week @ 2024-01-17 1147715/week @ 2024-01-24 1208649/week @ 2024-01-31 1213850/week @ 2024-02-07 1200504/week @ 2024-02-14 1339479/week @ 2024-02-21 1309652/week @ 2024-02-28 1293211/week @ 2024-03-06 1303012/week @ 2024-03-13 1307545/week @ 2024-03-20 1214681/week @ 2024-03-27 1302317/week @ 2024-04-03 1301051/week @ 2024-04-10 1306023/week @ 2024-04-17 1113565/week @ 2024-04-24

5,259,023 downloads per month
Used in 11,865 crates (1,457 directly)

MIT/Apache

54KB
976 lines

glob

Support for matching file paths against Unix shell style patterns.

Continuous integration

Documentation

Usage

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

[dependencies]
glob = "0.3.1"

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