std-function

fs::create_dir_all: ensure a directory tree

Create missing directory components. Failure may leave some created directories behind; it is not a transaction. Run only inside a disposable working directory. The fixture must not already exist. Expected stdout (not executed): true Common mistake: Assuming an error rolls back every created parent.

Formal Syntax & Structure

rust syntaxrust
fs::create_dir_all(path) -> io::Result<()>

Working Example

Example Snippetrust
fn main() {    use std::fs::{self, File, OpenOptions};    use std::io::{Read, Write};    fs::create_dir("bm-fixture").expect("use a fresh disposable directory");    let p = std::path::Path::new("bm-fixture").join("note.txt");    let d = p.with_file_name("one").join("two");    fs::create_dir_all(&d).unwrap();    println!("{}", d.is_dir());}
Rust Reference