/crates/ignore/README.md

https://github.com/BurntSushi/ripgrep · Markdown · 66 lines · 47 code · 19 blank · 0 comment · 0 complexity · 1e599e185f25e18e2e6dc0b951ceef02 MD5 · raw file

  1. ignore
  2. ======
  3. The ignore crate provides a fast recursive directory iterator that respects
  4. various filters such as globs, file types and `.gitignore` files. This crate
  5. also provides lower level direct access to gitignore and file type matchers.
  6. [![Linux build status](https://api.travis-ci.org/BurntSushi/ripgrep.svg)](https://travis-ci.org/BurntSushi/ripgrep)
  7. [![Windows build status](https://ci.appveyor.com/api/projects/status/github/BurntSushi/ripgrep?svg=true)](https://ci.appveyor.com/project/BurntSushi/ripgrep)
  8. [![](https://img.shields.io/crates/v/ignore.svg)](https://crates.io/crates/ignore)
  9. Dual-licensed under MIT or the [UNLICENSE](http://unlicense.org).
  10. ### Documentation
  11. [https://docs.rs/ignore](https://docs.rs/ignore)
  12. ### Usage
  13. Add this to your `Cargo.toml`:
  14. ```toml
  15. [dependencies]
  16. ignore = "0.4"
  17. ```
  18. and this to your crate root:
  19. ```rust
  20. extern crate ignore;
  21. ```
  22. ### Example
  23. This example shows the most basic usage of this crate. This code will
  24. recursively traverse the current directory while automatically filtering out
  25. files and directories according to ignore globs found in files like
  26. `.ignore` and `.gitignore`:
  27. ```rust,no_run
  28. use ignore::Walk;
  29. for result in Walk::new("./") {
  30. // Each item yielded by the iterator is either a directory entry or an
  31. // error, so either print the path or the error.
  32. match result {
  33. Ok(entry) => println!("{}", entry.path().display()),
  34. Err(err) => println!("ERROR: {}", err),
  35. }
  36. }
  37. ```
  38. ### Example: advanced
  39. By default, the recursive directory iterator will ignore hidden files and
  40. directories. This can be disabled by building the iterator with `WalkBuilder`:
  41. ```rust,no_run
  42. use ignore::WalkBuilder;
  43. for result in WalkBuilder::new("./").hidden(false).build() {
  44. println!("{:?}", result);
  45. }
  46. ```
  47. See the documentation for `WalkBuilder` for many other options.