44 releases (breaking)

new 0.92.2 Apr 10, 2024
0.91.0 Mar 5, 2024
0.88.1 Dec 14, 2023
0.87.1 Nov 20, 2023
0.60.0 Mar 22, 2022

#584 in Filesystem

Download history 1600/week @ 2023-12-20 1305/week @ 2023-12-27 1693/week @ 2024-01-03 2638/week @ 2024-01-10 1700/week @ 2024-01-17 1477/week @ 2024-01-24 1205/week @ 2024-01-31 2214/week @ 2024-02-07 1903/week @ 2024-02-14 1428/week @ 2024-02-21 1634/week @ 2024-02-28 2314/week @ 2024-03-06 1808/week @ 2024-03-13 1503/week @ 2024-03-20 1821/week @ 2024-03-27 2926/week @ 2024-04-03

8,402 downloads per month
Used in 59 crates (4 directly)

MIT/Apache

57KB
1K SLoC

nu-glob

Support for matching file paths against Unix shell style patterns.

Usage

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

[dependencies]
nu-glob = "0.60.0"

Examples

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

use nu_nu_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 nu_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 nu_glob::glob_with;
use nu_glob::MatchOptions;

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

No runtime deps