Function in io::fs compiler

is_file

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

Returns whether path is a regular file, following symbolic links.

A missing path is Ok(false). Needs --allow-read.

Parameters#

NameType
pathstring

Returns#

Result<bool, IoError>

Examples#

use io::fs::{is_file, remove_file};
use io::file::{write_text};
use tests::assert;
let path = "/tmp/coil_doc_fs_is_file.txt";
let _ = write_text(path, "x");
let file = match is_file(path) {
    Result::Ok(b) => b,
    Result::Err(_) => false,
};
let dir = match is_file("/tmp") {
    Result::Ok(b) => b,
    Result::Err(_) => true,
};
let _ = remove_file(path);
assert!(file && !dir);

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_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