#file-path #unix-shell #glob-pattern #pattern-matching #style #follow-links

glob-sl

Support for matching file paths against Unix shell style patterns

2 releases

Uses old Rust 2015

0.4.2 Sep 10, 2023
0.4.1 Apr 25, 2023
0.4.0 Apr 25, 2023

#1448 in Filesystem

Download history 5/week @ 2024-07-29 1/week @ 2024-08-05 58/week @ 2024-08-19 11/week @ 2024-09-23 2/week @ 2024-09-30 50/week @ 2024-10-14 234/week @ 2024-10-21

284 downloads per month
Used in 2 crates (via scandir)

MIT/Apache

54KB
987 lines

glob-sl

Support for matching file paths against Unix shell style patterns.

This crate is a fork of the glob crate. The only difference is that glob-rs add option follow_links to MatchOptions.

Build Status

Documentation

Usage

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

[dependencies]
glob-sl = "0.4.2"

And add this to your crate root:

extern crate glob_sl;

Examples

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

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