Created
December 24, 2017 21:42
-
-
Save Mic92/30d56aaffe50c279e6f809142929377b to your computer and use it in GitHub Desktop.
emulate mkdir -p in Rust (create directories recursivly and ignore an existing directory)
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::path::Path; | |
use std::fs::create_dir_all; | |
fn mkdir_p<P: AsRef<Path>>(path: &P) -> io::Result<()> { | |
if let Err(e) = create_dir_all(path) { | |
if e.kind() != io::ErrorKind::AlreadyExists { | |
return Err(e) | |
} | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: use
fs::create_dir_all
instead.When
path
is a exists file, theAlreadyExists
will be ignored.