Expand description
§GlobWalker
Fork of GlobWalk
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.
§Why not glob
- The
glob
crate does not support having{a,b}
in patterns. globwalker
can match several glob-patterns at the same time.globwalker
supports excluding results with!
.glob
searches for files in the current working directory, whereasglobwalker
starts at a specified base-dir.
§Usage
To use this crate, add globwalker
as a dependency to your project’s Cargo.toml
:
[dependencies]
globwalker = "0.9.0"
The following piece of code recursively find all png
, jpg
, or gif
files:
extern crate globwalker;
use std::fs;
for img in globwalker::glob("*.{png,jpg,gif}").unwrap() {
if let Ok(img) = img {
println!("{:?}", img);
}
}
See the documentation for more details. Recursively find files in a directory using globs.
Features include
gitignore
’s extended glob syntax- Control over symlink behavior
- Control depth walked
- Control order results are returned
§Examples
§Finding image files in the current directory.
extern crate globwalker;
use std::fs;
for img in globwalker::glob("*.{png,jpg,gif}")? {
if let Ok(img) = img {
fs::remove_file(img.path())?;
}
}
§Advanced Globbing
By using one of the constructors of globwalker::GlobWalker
, it is possible to alter the
base-directory or add multiple patterns.
extern crate globwalker;
use std::fs;
let walker = globwalker::GlobWalkerBuilder::from_patterns(
base_dir,
&["*.{png,jpg,gif}", "!Pictures/*"],
)
.max_depth(4)
.follow_links(true)
.build()?
.into_iter()
.filter_map(Result::ok);
for img in walker {
fs::remove_file(img.path())?;
}
Structs§
- File
Type - Possible file type filters. Constants can be OR’d to filter for several types at a time.
- Glob
Error - Error from parsing globs.
- Glob
Walker - An iterator which emits glob-matched patterns.
- Glob
Walker Builder - An iterator for recursively yielding glob matches.
Functions§
- glob
- Construct a new
GlobWalker
with a glob pattern. - glob_
builder - Construct a new
GlobWalkerBuilder
with a glob pattern.