To rename a directory in Rust, we first need to use the std::fs
module, which provides various utilities for working with the filesystem. In this case, we'll use the std::fs::rename
function, which allows us to rename a directory:
main.rs304 chars15 lines
In this example, we first specify the old directory name and the new directory name. We then call the fs::rename
function, passing in the old directory name and the new directory name as arguments. Finally, we use the ?
operator to propagate any errors that may occur.
Note that if the directory you're trying to rename doesn't exist, or if there's already a directory with the new name, an error will be returned.
gistlibby LogSnag