1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2024-12-02 02:56:32 +02:00
ripgrep/crates/ignore
2024-09-08 22:06:03 -04:00
..
examples ignore: polish 2023-10-09 20:29:52 -04:00
src ignore: add debug log message when opening gitignore file 2024-05-27 14:53:19 -04:00
tests edition: run 'cargo fix --edition --edition-idioms --all' 2021-06-01 21:07:37 -04:00
Cargo.toml ignore-0.4.23 2024-09-08 22:06:03 -04:00
COPYING
LICENSE-MIT
README.md edition: manual changes 2021-06-01 21:07:37 -04:00
UNLICENSE

ignore

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.

Build status

Dual-licensed under MIT or the UNLICENSE.

Documentation

https://docs.rs/ignore

Usage

Add this to your Cargo.toml:

[dependencies]
ignore = "0.4"

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.