Function std::old_io::fs::copyUnstable
[-] [+]
[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::old_io::fs; fs::copy(&Path::new("foo.txt"), &Path::new("bar.txt")); }use std::old_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
from
path is not a file - The
from
file does not exist - The current process does not have the permission rights to access
from
or 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.