-
Open the Cargo.toml file that was generated earlier for you.
- Under [dependencies], add the following line:
walkdir = "2.0.1"
- If you want, you can go to walkdir's crates.io page (https://crates.io/crates/walkdir) to check for the newest version and use that one instead.
-
In the bin folder, create a file called traverse_files.rs.
-
Add the following code and run it with cargo run --bin traverse_files:
1 extern crate walkdir;
2 use walkdir::{DirEntry, WalkDir};
3
4 fn main() {
5 println!("All file paths in this directory:");
6 for entry in WalkDir::new(".") {
7 if let Ok(entry) = entry {
8 println!("{}", entry.path().display());
9 }
10 }
11
12 println!("All non-hidden file names in this directory:");
13 WalkDir::new("../chapter_three")
14 .into_iter()
15 .filter_entry(|entry| !is_hidden(entry)) // Look only at
non-hidden enthries...