Skip to content

Instantly share code, notes, and snippets.

@rust-play
Created January 26, 2025 19:24
Show Gist options
  • Save rust-play/c5503d01e3e0885ec58539ede1c1892b to your computer and use it in GitHub Desktop.
Save rust-play/c5503d01e3e0885ec58539ede1c1892b to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
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