Reference · reference
fs module
use fs gives a script file input and output. It replaces the standalone fs module of wscript-std, which config-weave does not register. Every function that can fail returns Result[…, string], where the error string names the path and the operating system error. The predicates exists, is_file and is_dir return a plain bool. Path strings are passed through to the operating system unchanged; use the path module to build them.
read and read_bytes
read
read_bytes
read returns the file as text. read_bytes returns the raw bytes as a list of integers.
write, write_bytes and append
write
write_bytes
append
write and write_bytes replace the file's contents. append adds text to the end of the file and creates the file when it is absent.
copy and move
copy
move
copy copies one file. move renames a file or a directory.
delete and delete_dir
delete
delete_dir
delete removes a file or a symlink. delete_dir removes a directory and everything in it.
mkdir
mkdir
Creates a directory, including any missing parents.
exists, is_file and is_dir
exists is_file is_dir Each predicate answers one question about a path. A path that cannot be read answers false.
list_dir
list_dir
Returns the names of the entries in a directory, sorted.
metadata
metadata
Returns a map describing the path. Read it with the accessors of the Value type.
| Key | Type | Meaning |
|---|---|---|
| size | int | size in bytes |
| modified | int | modification time, seconds since the Unix epoch |
| readonly | bool | the read-only attribute |
| is_file | bool | the path is a regular file |
| is_dir | bool | the path is a directory |
| is_symlink | bool | the path is a symlink |
| mode | int | Unix permission bits, 0 on other platforms |
glob
glob
Expands a glob pattern to the matching paths, sorted.
temp_file and temp_dir
temp_file
temp_dir
Each creates a fresh temporary file or directory and returns its path.
symlink and read_link
symlink
read_link
symlink creates a link at link that points to target. read_link returns the target a symlink points to.
use fs
use hash
let path = "/etc/app/app.conf"
if !is_file
let current = sha256_file?
let wanted = sha256
if current == wanted else
}