29 releases

Uses old Rust 2015

0.3.3 Aug 11, 2025
0.3.2 Dec 29, 2024
0.3.1 Jan 6, 2023
0.3.0 Mar 7, 2019
0.1.0 Nov 27, 2014

#7 in Filesystem

Download history 4028774/week @ 2025-11-01 3948471/week @ 2025-11-08 3950560/week @ 2025-11-15 3436376/week @ 2025-11-22 3745742/week @ 2025-11-29 4137871/week @ 2025-12-06 4114964/week @ 2025-12-13 2408247/week @ 2025-12-20 2251571/week @ 2025-12-27 4194731/week @ 2026-01-03 4711276/week @ 2026-01-10 4751738/week @ 2026-01-17 5103956/week @ 2026-01-24 5359419/week @ 2026-01-31 5638948/week @ 2026-02-07 5255029/week @ 2026-02-14

22,226,805 downloads per month
Used in 23,256 crates (2,812 directly)

MIT/Apache

57KB
1K SLoC

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())
    }
}

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.2"

If you're using Rust 1.30 or earlier, or edition 2015, 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),
    }
}

No runtime deps