28 releases

Uses old Rust 2015

0.3.2 Dec 29, 2024
0.3.1 Jan 6, 2023
0.3.0 Mar 7, 2019
0.2.11 Mar 6, 2016
0.1.0 Nov 27, 2014

#6 in Filesystem

Download history 1835013/week @ 2024-10-29 1812925/week @ 2024-11-05 1830796/week @ 2024-11-12 1784855/week @ 2024-11-19 1539061/week @ 2024-11-26 1828665/week @ 2024-12-03 1920555/week @ 2024-12-10 1783932/week @ 2024-12-17 951950/week @ 2024-12-24 1334939/week @ 2024-12-31 2191222/week @ 2025-01-07 2071203/week @ 2025-01-14 2054147/week @ 2025-01-21 2141066/week @ 2025-01-28 2375002/week @ 2025-02-04 2362362/week @ 2025-02-11

9,231,711 downloads per month
Used in 15,899 crates (1,787 directly)

MIT/Apache

56KB
1K SLoC

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"

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

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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy