57 releases (breaking)

0.100.0 Nov 13, 2024
0.98.0 Sep 18, 2024
0.96.1 Jul 29, 2024
0.91.0 Mar 5, 2024
0.60.0 Mar 22, 2022

#415 in Filesystem

Download history 2593/week @ 2024-08-21 1951/week @ 2024-08-28 1562/week @ 2024-09-04 1680/week @ 2024-09-11 2987/week @ 2024-09-18 2493/week @ 2024-09-25 1971/week @ 2024-10-02 1995/week @ 2024-10-09 3044/week @ 2024-10-16 2070/week @ 2024-10-23 2617/week @ 2024-10-30 1891/week @ 2024-11-06 2516/week @ 2024-11-13 2292/week @ 2024-11-20 2767/week @ 2024-11-27 2098/week @ 2024-12-04

9,869 downloads per month
Used in 95 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