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

#5 in Filesystem

Download history 1553915/week @ 2024-07-23 1583053/week @ 2024-07-30 1607577/week @ 2024-08-06 1597475/week @ 2024-08-13 1679056/week @ 2024-08-20 1602278/week @ 2024-08-27 1708458/week @ 2024-09-03 1651466/week @ 2024-09-10 1693924/week @ 2024-09-17 1847411/week @ 2024-09-24 2241974/week @ 2024-10-01 2537386/week @ 2024-10-08 2350292/week @ 2024-10-15 1844229/week @ 2024-10-22 1835013/week @ 2024-10-29 1812864/week @ 2024-11-05

8,275,555 downloads per month
Used in 14,091 crates (1,680 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