Skip to content

Instantly share code, notes, and snippets.

@wulfgarpro
Created January 9, 2023 22:41
Show Gist options
  • Save wulfgarpro/f747b8ca562a29b5b754e721188cb3e8 to your computer and use it in GitHub Desktop.
Save wulfgarpro/f747b8ca562a29b5b754e721188cb3e8 to your computer and use it in GitHub Desktop.
Build a matcher for a set of glob overrides using the `ignore` crate.
use ignore::WalkBuilder;
use ignore::overrides::OverrideBuilder;
fn main() {
let folder = "/tmp/files";
let mut override_builder = OverrideBuilder::new(folder);
override_builder.add("!test.txt").unwrap();
override_builder.add("!test.rs").unwrap();
let or = override_builder.build().unwrap();
let mut builder = WalkBuilder::new(folder);
builder.overrides(or);
builder.standard_filters(false);
for result in builder.build() {
let dent = result.unwrap();
println!("{}", dent.path().display());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment