#glob-pattern #file-path #unix-shell #style #matching #fork #jpeg

globetter

Glob fork with bug fixes! Support for matching file paths against Unix shell style patterns

3 unstable releases

Uses old Rust 2015

0.2.0 Dec 2, 2022
0.1.1 Oct 7, 2022
0.1.0 Oct 4, 2022

#1282 in Filesystem

Download history 45/week @ 2024-07-20 23/week @ 2024-07-27 48/week @ 2024-08-03 26/week @ 2024-08-10 85/week @ 2024-08-17 45/week @ 2024-08-24 58/week @ 2024-08-31 32/week @ 2024-09-07 37/week @ 2024-09-14 36/week @ 2024-09-21 42/week @ 2024-09-28 22/week @ 2024-10-05 52/week @ 2024-10-12 18/week @ 2024-10-19 59/week @ 2024-10-26 21/week @ 2024-11-02

153 downloads per month
Used in ludusavi

MIT/Apache

63KB
1K SLoC

Globetter

This is a minimal fork of the Glob crate. As of 2022-10-04, its last release was 2019-03-07, and there are some outstanding defects. This fork is intended as a drop-in replacement for bug fixes, detailed in the changelog and releases page.

Support for matching file paths against Unix shell style patterns.

Documentation

Usage

To use globetter, add it to your project by running cargo add globetter.

Examples

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

use globetter::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 globetter::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 globetter::glob_with;
use globetter::MatchOptions;

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

No runtime deps