Skip to content

Instantly share code, notes, and snippets.

@RandyMcMillan
Forked from rust-play/playground.rs
Last active January 26, 2025 19:26
Show Gist options
  • Save RandyMcMillan/8e20f6cefa906367b2506aedd78970fd to your computer and use it in GitHub Desktop.
Save RandyMcMillan/8e20f6cefa906367b2506aedd78970fd to your computer and use it in GitHub Desktop.
walk_dir.rs
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