copy
fn copy(string from, string to) -> Result<unit, IoError> Import
Source: use io::fs::{copy}; compiler/src/builtin_docs/io/fs.hy Copies the contents of file from to to, creating or overwriting to.
Copies file contents and permissions; it does not copy directories.
Returns Err(IoError::NotFound) when from does not exist.
A program that reaches copy compiles only with both --allow-read
and --allow-write.
Parameters#
| Name | Type |
|---|---|
from | string |
to | string |
Returns#
Result<unit, IoError>
Examples#
use io::fs::{copy, create_dir_all, remove_dir_all};
use io::file::{read_text, write_text};
use tests::assert;
let dir = "/tmp/coil_doc_fs_copy";
let _ = create_dir_all(dir);
let _ = write_text("/tmp/coil_doc_fs_copy/a.txt", "data");
let _ = copy("/tmp/coil_doc_fs_copy/a.txt", "/tmp/coil_doc_fs_copy/b.txt");
let text = match read_text("/tmp/coil_doc_fs_copy/b.txt") {
Result::Ok(t) => t,
Result::Err(_) => "",
};
let _ = remove_dir_all(dir);
assert!(text == "data");
See also#
create_dir: Creates the directorypath.create_dir_all: Creates the directorypathand any missing parent directories.exists: Returns whether anything exists atpath.is_dir: Returns whetherpathis a directory, following symbolic links.is_file: Returns whetherpathis a regular file, following symbolic links.is_symlink: Returns whetherpathitself is a symbolic link (the link is not followed).list_dir: Returns the names of the entries in directorypath, sorted.metadata: Returns facts aboutpathas a record, without following a final symbolic link.