Expand description
The ignore crate provides a fast recursive directory iterator that respects
various filters such as globs, file types and .gitignore
files. The precise
matching rules and precedence is explained in the documentation for
WalkBuilder
.
Secondarily, this crate exposes gitignore and file type matchers for use cases that demand more fine-grained control.
Example
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),
}
}
Example: advanced
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.
Modules
- The gitignore module provides a way to match globs from a gitignore file against file paths.
- The overrides module provides a way to specify a set of override globs. This provides functionality similar to
--include
or--exclude
in command line tools. - The types module provides a way of associating globs on file names to file types.
Structs
- A directory entry with a possible error attached.
- Walk is a recursive directory iterator over file paths in one or more directories.
- WalkBuilder builds a recursive directory iterator.
- WalkParallel is a parallel recursive directory iterator over files paths in one or more directories.
Enums
- Represents an error that can occur when parsing a gitignore file.
- The result of a glob match.
- WalkState is used in the parallel recursive directory iterator to indicate whether walking should continue as normal, skip descending into a particular directory or quit the walk entirely.
Traits
- Receives files and directories for the current thread.
- A builder for constructing a visitor when using
WalkParallel::visit
. The builder will be called for each thread started byWalkParallel
. The visitor returned from each builder is then called for every directory entry.