-
-
Save RandyMcMillan/8e20f6cefa906367b2506aedd78970fd to your computer and use it in GitHub Desktop.
walk_dir.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::fs; | |
use std::path::Path; | |
fn main() { | |
let input = "/usr/share/doc"; | |
fn action(path: &str) { println!("\t{}" , path); } | |
fn walk(path: &str) { | |
println!("Listing {} ..." , path); | |
for entry in fs::read_dir(&Path::new(&path)).unwrap() { | |
let entry = entry.unwrap(); | |
if fs::metadata(&entry.path()).unwrap().is_dir() { | |
walk(&entry.path().to_str().unwrap()); | |
} else { action(&entry.path().as_path().to_str().unwrap()); } | |
} | |
} | |
walk(input); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment