Crates.io | ignore |
lib.rs | ignore |
version | 0.4.23 |
source | src |
created_at | 2016-10-30 02:14:00.0699 |
updated_at | 2024-09-09 02:06:06.387704 |
description | A fast library for efficiently matching ignore files such as `.gitignore` against file paths. |
homepage | https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore |
repository | https://github.com/BurntSushi/ripgrep/tree/master/crates/ignore |
max_upload_size | |
id | 7045 |
size | 245,350 |
The ignore crate provides a fast recursive directory iterator that respects
various filters such as globs, file types and .gitignore
files. This crate
also provides lower level direct access to gitignore and file type matchers.
Dual-licensed under MIT or the UNLICENSE.
Add this to your Cargo.toml
:
[dependencies]
ignore = "0.4"
This example shows the most basic usage of this crate. This code will
recursively traverse the current directory while automatically filtering out
files and directories according to ignore globs found in files like
.ignore
and .gitignore
:
use ignore::Walk;
for result in Walk::new("./") {
// Each item yielded by the iterator is either a directory entry or an
// error, so either print the path or the error.
match result {
Ok(entry) => println!("{}", entry.path().display()),
Err(err) => println!("ERROR: {}", err),
}
}
By default, the recursive directory iterator will ignore hidden files and
directories. This can be disabled by building the iterator with WalkBuilder
:
use ignore::WalkBuilder;
for result in WalkBuilder::new("./").hidden(false).build() {
println!("{:?}", result);
}
See the documentation for WalkBuilder
for many other options.