Skip to main content

rename

Function rename 

Source
pub fn rename(from: impl AsRef<Path>, to: impl AsRef<Path>) -> Result<()>
Available on crate feature fs only.
Expand description

Move a file or directory.

Unlike std::fs::rename, this will fallback to less efficient methods of moving if the paths are on separate file systems. Currently, renaming directories on separate filesystems is not supported to prevent unintended behavior.

§If from is file

  • will error if to is a directory
  • to will be replaced if exists

§If from is a directory

  • will error if to exists and is not a directory or is a non-empty directory (use cu::fs::rec_remove(to) to delete it first), or is on a different filesystem than from.