#shell #glob #jpeg #unix #patterns #media #nu

nu-glob

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

20 releases (breaking)

0.75.0 Jan 31, 2023
0.73.0 Dec 20, 2022
0.72.0 Nov 29, 2022
0.66.2 Jul 28, 2022
0.60.0 Mar 22, 2022

#63 in Filesystem

Download history 837/week @ 2022-10-19 574/week @ 2022-10-26 626/week @ 2022-11-02 861/week @ 2022-11-09 618/week @ 2022-11-16 514/week @ 2022-11-23 840/week @ 2022-11-30 576/week @ 2022-12-07 420/week @ 2022-12-14 737/week @ 2022-12-21 563/week @ 2022-12-28 561/week @ 2023-01-04 931/week @ 2023-01-11 636/week @ 2023-01-18 681/week @ 2023-01-25 1150/week @ 2023-02-01

3,532 downloads per month
Used in 25 crates (4 directly)

MIT/Apache

45KB
813 lines

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