metadata
fn metadata(string path) -> Result<Metadata, IoError> Import
Source: use io::fs::{metadata}; 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#
| Name | Type |
|---|---|
path | string |
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#
io::fs::is_fileio::fs::is_dirio::fs::is_symlinkcopy: 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.list_dir: Returns the names of the entries in directorypath, sorted.