Function std::fs::rename
[−]
[src]
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<()>1.0.0
Rename a file or directory to a new name.
This will not work if the new name is on a different mount point.
Platform-specific behavior
This function currently corresponds to the rename function on Unix
and the MoveFileEx function with the MOVEFILE_REPLACE_EXISTING flag on Windows.
Note that, this may change in the future.
Errors
This function will return an error in the following situations, but is not limited to just these cases:
fromdoes not exist.- The user lacks permissions to view contents.
fromandtoare on separate filesystems.
Examples
fn main() { use std::fs; fn foo() -> std::io::Result<()> { try!(fs::rename("a.txt", "b.txt")); // Rename a.txt to b.txt Ok(()) } }use std::fs; try!(fs::rename("a.txt", "b.txt")); // Rename a.txt to b.txt