#shell #glob #pattern #join-pattern

nu-glob

Fork of glob. Support for matching file paths against Unix shell style patterns.

35 releases (breaking)

0.87.1 Nov 20, 2023
0.86.0 Oct 17, 2023
0.83.1 Jul 30, 2023
0.77.1 Mar 17, 2023
0.60.0 Mar 22, 2022

#348 in Filesystem

Download history 990/week @ 2023-08-09 1203/week @ 2023-08-16 2184/week @ 2023-08-23 1645/week @ 2023-08-30 1565/week @ 2023-09-06 1996/week @ 2023-09-13 2114/week @ 2023-09-20 1587/week @ 2023-09-27 1312/week @ 2023-10-04 1643/week @ 2023-10-11 2352/week @ 2023-10-18 1699/week @ 2023-10-25 1747/week @ 2023-11-01 2021/week @ 2023-11-08 3262/week @ 2023-11-15 1974/week @ 2023-11-22

9,261 downloads per month
Used in 53 crates (5 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