Skip to content

Instantly share code, notes, and snippets.

@vcsjones

vcsjones/foo.rs Secret

Created December 5, 2019 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vcsjones/510719f51816cc7570b8c251449fc0b7 to your computer and use it in GitHub Desktop.
Save vcsjones/510719f51816cc7570b8c251449fc0b7 to your computer and use it in GitHub Desktop.
use std::fs::read_dir;
fn main() {
match print_paths("special") {
Ok(()) => println!("Done"),
Err(a) => println!("Errors happened: {}", a)
}
}
fn print_paths(path : &str) -> Result<(), std::io::Error> {
let paths = read_dir(path)?;
for path in paths {
let path_buf = path?.path();
if let Some(name) = path_buf.to_str() {
println!("Name: {}", name);
} else {
println!("Closest name: {}", path_buf.to_string_lossy())
}
}
Ok(())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment