Recursively find files in a directory using globs.
Based on both walkdir
& ignore
(โค), this crate inherits many goodies from
both, such as limiting search depth and amount of open file descriptors.
Licensed under MIT.
- The
glob
crate does not support having{a,b}
in patterns. globwalk
can match several glob-patterns at the same time.globwalk
supports excluding results with!
.glob
searches for files in the current working directory, whereasglobwalk
starts at a specified base-dir.
To use this crate, add globwalk
as a dependency to your project's Cargo.toml
:
[dependencies]
globwalk = "0.3"
The following piece of code recursively find all mp3 and FLAC files:
extern crate globwalk;
use std::fs;
for img in globwalk::glob("*.{png,jpg,gif}").unwrap() {
if let Ok(img) = img {
fs::remove_file(img.path()).unwrap();
}
}
See the documentation for more details.