Function std::io::fs::copyExperimental
[-]
[+]
[src]
pub fn copy(from: &Path, to: &Path) -> IoResult<()>
Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.
Note that if from and to both point to the same file, then the file
will likely get truncated by this operation.
Example
fn main() { #![allow(unused_must_use)] use std::io::fs; fs::copy(&Path::new("foo.txt"), &Path::new("bar.txt")); }use std::io::fs; fs::copy(&Path::new("foo.txt"), &Path::new("bar.txt"));
Error
This function will return an error in the following situations, but is not limited to just these cases:
- The
frompath is not a file - The
fromfile does not exist - The current process does not have the permission rights to access
fromor writeto
Note that this copy is not atomic in that once the destination is ensured to not exist, there is nothing preventing the destination from being created and then destroyed by this operation.