Function in io::fs compiler

exists

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

Returns whether anything exists at path.

Follows symbolic links, so a link whose target is missing gives Ok(false). A missing path is Ok(false), not an error; other OS errors (such as PermissionDenied) are returned as Err. Needs --allow-read.

Parameters#

NameType
pathstring

Returns#

Result<bool, IoError>

Examples#

use io::fs::{exists};
use tests::assert;
let tmp = match exists("/tmp") {
    Result::Ok(b) => b,
    Result::Err(_) => false,
};
let missing = match exists("/tmp/coil_doc_fs_no_such_file") {
    Result::Ok(b) => b,
    Result::Err(_) => true,
};
assert!(tmp && !missing);

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.
  • 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