Function rename

pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<()>

Renames a file or directory to a new name, replacing the original file if to already exists.

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 MoveFileExW with a fallback to SetFileInformationByHandle on Windows. The exact behavior differs:

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:

Examples

use std::fs;

fn main() -> std::io::Result<()> {
    fs::rename("a.txt", "b.txt")?; // Rename a.txt to b.txt
    Ok(())
}