Function in io::fs compiler

metadata

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

Returns facts about path as a record, without following a final symbolic link.

Fields: size (bytes), is_file, is_dir, is_symlink, and modified_unix (last modification time in whole seconds since the Unix epoch, or 0 when the OS does not report it). For a symbolic link the record describes the link itself, so is_symlink is true. Returns Err(IoError::NotFound) for a missing path. Needs --allow-read.

The record type has no name: Metadata in the signature above stands for { size: int, is_file: bool, is_dir: bool, is_symlink: bool, modified_unix: int }.

Parameters#

NameType
pathstring

Returns#

Result<Metadata, IoError>

Examples#

use io::fs::{metadata, remove_file};
use io::file::{write_text};
use tests::assert;
let path = "/tmp/coil_doc_fs_metadata.txt";
let _ = write_text(path, "abcd");
let (size, file) = match metadata(path) {
    Result::Ok(m) => (m.size, m.is_file),
    Result::Err(_) => (0, false),
};
let _ = remove_file(path);
assert!(size == 4 && file);

See also#

↑ ↓ navigate ↵ open