Function in io::fs compiler

remove_file

fn remove_file(string path) -> Result<unit, IoError>
Import
use io::fs::{remove_file};
Source: compiler/src/builtin_docs/io/fs.hy

Removes the file (or symbolic link) at path.

A symbolic link is removed itself, not its target. Returns Err(IoError::NotFound) when nothing is there. Needs --allow-write.

Parameters#

NameType
pathstring

Returns#

Result<unit, IoError>

Examples#

use io::{IoError};
use io::fs::{remove_file};
use io::file::{write_text};
use tests::assert;
let path = "/tmp/coil_doc_fs_remove_file.txt";
let _ = write_text(path, "x");
let removed = match remove_file(path) {
    Result::Ok(_) => true,
    Result::Err(_) => false,
};
let again = match remove_file(path) {
    Result::Err(IoError::NotFound) => true,
    default => false,
};
assert!(removed && again);

See also#

  • copy: Copies the contents of file from to to, creating or overwriting to.
  • 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.
↑ ↓ navigate ↵ open