Expand description
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, Uninterruptible};
for entry in glob("/media/**/*.jpg", Uninterruptible).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, MatchOptions, Uninterruptible};
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, Uninterruptible).unwrap() {
if let Ok(path) = entry {
println!("{:?}", path.display())
}
}Structs§
- Glob
Error - A glob iteration error.
- Match
Options - Configuration options to modify the behaviour of
Pattern::matches_with(..). - Paths
- An iterator that yields
Paths from the filesystem that match a particular pattern. - Pattern
- A compiled Unix shell style pattern.
- Pattern
Error - A pattern parsing error.
- Uninterruptible
- A no-op implementor of
Interruptiblethat always returnsfalseforinterrupted.
Traits§
- Interruptible
- A trait for types that can be periodically polled to check whether to cancel an operation.
Functions§
- glob
- Return an iterator that produces all the
Paths that match the given pattern using default match options, which may be absolute or relative to the current working directory. - glob_
with - Return an iterator that produces all the
Paths that match the given pattern using the specified match options, which may be absolute or relative to the current working directory. - glob_
with_ parent - Return an iterator that produces all the
Paths that match the given pattern relative to a specified parent directory and using specified match options. Paths may be absolute or relative to the current working directory. - is_glob
- Returns true if the given pattern is a glob, false if it’s merely text to be matched exactly.
Type Aliases§
- Glob
Result - An alias for a glob iteration result.