Function std::fs::copy [] [src]

pub fn copy<P: AsRef<Path>, Q: AsRef<Path>>(from: P, to: Q) -> Result<u64>
1.0.0

Copies the contents of one file to another. This function will also copy the permission bits of the original file to the destination file.

This function will overwrite the contents of to.

Note that if from and to both point to the same file, then the file will likely get truncated by this operation.

On success, the total number of bytes copied is returned.

Platform-specific behavior

This function currently corresponds to the open function in Unix with O_RDONLY for from and O_WRONLY, O_CREAT, and O_TRUNC for to. O_CLOEXEC is set for returned file descriptors. On Windows, this function currently corresponds to CopyFileEx. 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

fn main() { use std::fs; fn foo() -> std::io::Result<()> { try!(fs::copy("foo.txt", "bar.txt")); // Copy foo.txt to bar.txt Ok(()) } }
use std::fs;

try!(fs::copy("foo.txt", "bar.txt"));  // Copy foo.txt to bar.txt