Traversing the filesystem
Up until now, we always provided our code with the static location of a certain file. Alas, the real world is seldom so predictable, and some digging is going to be necessary when dealing with data scattered throughout different folders.
walkdir
helps us with this by abstracting away the intricacies and inconsistencies of operating systems' representation of the filesystem by unifying them under one common API, which we are going to learn about in this recipe.
Getting ready
This recipe makes heavy use of iterators to manipulate streams of data. If you are not yet familiar with them or need a quick refresher, you should read the Access collections as Iterators section in Chapter 2, Working with Collections, before continuing.
How to do it...
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...