To delete a directory in Rust, you can use the std::fs::remove_dir
function. It takes a path to the directory as an argument and returns a Result<(), std::io::Error>
.
main.rs132 chars8 lines
Note that the function will fail if the directory is not empty. To recursively delete a directory and all its content, you can use the std::fs::remove_dir_all
function:
main.rs156 chars8 lines
Both functions return an std::io::Error
if something goes wrong during the deletion, so it's important to handle the result properly.
gistlibby LogSnag