A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://doc.rust-lang.org/nightly/std/fs/fn.rename.html below:

rename in std::fs - Rust

Function rename1.0.0 · Source
pub fn rename<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<()>
Expand description

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 the MoveFileExW or SetFileInformationByHandle function on Windows.

Because of this, the behavior when both from and to exist differs. On Unix, if from is a directory, to must also be an (empty) directory. If from is not a directory, to must also be not a directory. The behavior on Windows is the same on Windows 10 1607 and higher if FileRenameInfoEx is supported by the filesystem; otherwise, from can be anything, but to must not be a directory.

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")?; 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