Function copy_file

Source
pub fn copy_file<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q)
Expand description

Copies a file from one location to another.

§Arguments

§Panics

If the source file does not exist or cannot be accessed, or if the destination cannot be created.

§Note

  • The parent folder for the destination file will be created if it does not already exist.
  • If the destination file already exists, it will be overwritten.

§Examples

§Using string literals

use file_io::copy_file;

// Copy 'Cargo.toml' to 'folder/Cargo_new_1.toml'.
let from: &str = "Cargo.toml";
let to: &str = "folder/Cargo_new_1.toml";
copy_file(from, to);

§Using Path references

use file_io::copy_file;
use std::path::Path;

// Copy 'Cargo.toml' to 'folder/Cargo_new_2.toml'.
let from: &Path = Path::new("Cargo.toml");
let to: &Path = Path::new("folder/Cargo_new_2.toml");
copy_file(from, to);