How to walk directory tree

Walk a directory tree in Rust using the walkdir crate to recursively list all files and folders.

Use the walkdir crate to recursively iterate over files and directories in a tree structure. Add walkdir to your dependencies and use DirEntry to access file metadata and paths.

use walkdir::WalkDir;

fn main() {
    for entry in WalkDir::new(".") {
        let entry = entry.unwrap();
        println!("{:?}", entry.path());
    }
}