Skip to content

Instantly share code, notes, and snippets.

@danmack
Created August 22, 2017 12:12
Show Gist options
  • Save danmack/85a2b096926082fcfdddf59adbb0eaa9 to your computer and use it in GitHub Desktop.
Save danmack/85a2b096926082fcfdddf59adbb0eaa9 to your computer and use it in GitHub Desktop.
use std::path::Path;
fn main() {
let path = Path::new("./package");
if path.exists() {
if path.is_dir() {
println!("{:?} is a directory", path);
} else {
println!("{:?} is not a directory", path);
}
} else {
println!("{:?} does not exist", path);
}
}
/* example:
$ touch package
$ ./target/debug/myisdir
"./package" is not a directory
$ rm package
$ mkdir package
$ ./target/debug/myisdir
"./package" is a directory
$ rm -rf package
$ ./target/debug/myisdir
"./package" does not exist
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment