| 1 |
glob |
| 2 |
==== |
| 3 |
|
| 4 |
Support for matching file paths against Unix shell style patterns. |
| 5 |
|
| 6 |
[](https://github.com/rust-lang/glob/actions/workflows/rust.yml) |
| 7 |
|
| 8 |
[Documentation](https://docs.rs/glob) |
| 9 |
|
| 10 |
## Usage |
| 11 |
|
| 12 |
To use `glob`, add this to your `Cargo.toml`: |
| 13 |
|
| 14 |
```toml |
| 15 |
[dependencies] |
| 16 |
glob = "0.3.1" |
| 17 |
``` |
| 18 |
|
| 19 |
And add this to your crate root: |
| 20 |
|
| 21 |
```rust |
| 22 |
extern crate glob; |
| 23 |
``` |
| 24 |
|
| 25 |
## Examples |
| 26 |
|
| 27 |
Print all jpg files in /media/ and all of its subdirectories. |
| 28 |
|
| 29 |
```rust |
| 30 |
use glob::glob; |
| 31 |
|
| 32 |
for entry in glob("/media/**/*.jpg").expect("Failed to read glob pattern") { |
| 33 |
match entry { |
| 34 |
Ok(path) => println!("{:?}", path.display()), |
| 35 |
Err(e) => println!("{:?}", e), |
| 36 |
} |
| 37 |
} |
| 38 |
``` |