-
-
Save rust-play/c5503d01e3e0885ec58539ede1c1892b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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