Last active
February 3, 2019 17:07
-
-
Save voldyman/47380099f8be05b6de0e3880e043c46c to your computer and use it in GitHub Desktop.
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::io; | |
use std::env; | |
use std::fs::{self, DirEntry}; | |
use std::path::Path; | |
fn visit_dirs(dir: &Path, cb: &Fn(&DirEntry)) -> io::Result<()> { | |
if dir.is_dir() { | |
for entry in fs::read_dir(dir)? { | |
let entry = entry?; | |
let path = entry.path(); | |
if let Some(filename) = path.file_name().and_then(|s| s.to_str()) { | |
if filename.starts_with(".") { | |
continue; | |
} | |
} | |
if path.is_dir() { | |
visit_dirs(&path, cb)?; | |
} else { | |
cb(&entry); | |
} | |
} | |
} | |
Ok(()) | |
} | |
fn main() { | |
let args : Vec<String> = env::args().collect(); | |
if args.len() < 2 { | |
println!("Usage: {} <dirname>", args[0]); | |
return | |
} | |
visit_dirs(Path::new(&args[1]), &|entry : &DirEntry| { | |
println!("{}", entry.path().to_str().expect("Path should be a valid string")); | |
}).expect("Current dir not found"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment