std-function
fs::remove_dir_all: remove an owned fixture tree
Recursively remove an explicitly owned directory tree; errors may leave a partial tree. Never use untrusted paths or shared learner directories. Use a fresh disposable working directory exclusively controlled by this program. Expected stdout (not executed): false Common mistake: Using recursive deletion as a generic cleanup of arbitrary user input.
Formal Syntax & Structure
rust syntaxrust
fs::remove_dir_all(path) -> io::Result<()>Working Example
Example Snippetrust
fn main() { use std::fs::{self, File}; use std::io::{Read, Write}; fs::create_dir("bm-fixture").expect("fresh working directory required"); let p = std::path::Path::new("bm-fixture").join("note.txt"); let d = p.with_file_name("disposable"); fs::create_dir(&d).unwrap(); File::create_new(d.join("one.txt")).unwrap(); fs::remove_dir_all(&d).unwrap(); println!("{}", d.try_exists().unwrap());}