Function remove_dir_all

fn remove_dir_all<P: AsRef<crate::path::Path>>(path: P) -> io::Result<()>

Removes a directory at this path, after removing all its contents. Use carefully!

This function does not follow symbolic links and it will simply remove the symbolic link itself.

Platform-specific behavior

These implementation details may change in the future.

Time-of-check to time-of-use (TOCTOU) race conditions

See the module-level TOCTOU explanation.

On most platforms, fs::remove_dir_all protects against symlink TOCTOU races by default. However, on the following platforms, this protection is not provided and the function should not be used in security-sensitive contexts:

Errors

See fs::remove_file and fs::remove_dir.

remove_dir_all will fail if remove_dir or remove_file fail on any constituent paths, including the root path. Consequently,

Consider ignoring the error if validating the removal is not required for your use case.

This function may return io::ErrorKind::DirectoryNotEmpty if the directory is concurrently written into, which typically indicates some contents were removed but not all. io::ErrorKind::NotFound is only returned if no removal occurs.

Examples

use std::fs;

fn main() -> std::io::Result<()> {
    fs::remove_dir_all("/some/dir")?;
    Ok(())
}