Function in io::fs compiler

copy

fn copy(string from, string to) -> Result<unit, IoError>
Import
use io::fs::{copy};
Source: 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#

NameType
fromstring
tostring

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 directory path.
  • create_dir_all: Creates the directory path and any missing parent directories.
  • exists: Returns whether anything exists at path.
  • is_dir: Returns whether path is a directory, following symbolic links.
  • is_file: Returns whether path is a regular file, following symbolic links.
  • is_symlink: Returns whether path itself is a symbolic link (the link is not followed).
  • list_dir: Returns the names of the entries in directory path, sorted.
  • metadata: Returns facts about path as a record, without following a final symbolic link.
↑ ↓ navigate ↵ open