pub fn remove_dir_all<P: AsRef<Path>>(path: P) -> Result<()>
Expand description
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 behaviorThese implementation details may change in the future.
openat
, fdopendir
, unlinkat
and lstat
on Unix-family platforms, except where noted otherwise.CreateFileW
, GetFileInformationByHandleEx
, SetFileInformationByHandle
, and NtCreateFile
.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:
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,
remove_dir_all
will fail if the path
is not a directory.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.
use std::fs;
fn main() -> std::io::Result<()> {
fs::remove_dir_all("/some/dir")?;
Ok(())
}
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4