rename
fn rename(string from, string to) -> Result<unit, IoError> Import
Source: use io::fs::{rename}; compiler/src/builtin_docs/io/fs.hy Renames (moves) from to to, replacing to if it is a file.
Works for files and directories. Moving across file systems fails.
Needs --allow-write.
Parameters#
| Name | Type |
|---|---|
from | string |
to | string |
Returns#
Result<unit, IoError>
Examples#
use io::fs::{exists, remove_file, rename};
use io::file::{write_text};
use tests::assert;
let _ = write_text("/tmp/coil_doc_fs_rename_a.txt", "x");
let moved = match rename("/tmp/coil_doc_fs_rename_a.txt", "/tmp/coil_doc_fs_rename_b.txt") {
Result::Ok(_) => true,
Result::Err(_) => false,
};
let new_there = match exists("/tmp/coil_doc_fs_rename_b.txt") {
Result::Ok(b) => b,
Result::Err(_) => false,
};
let _ = remove_file("/tmp/coil_doc_fs_rename_b.txt");
assert!(moved && new_there);
See also#
copy: Copies the contents of filefromtoto, creating or overwritingto.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.