veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

fs

lib/fs.vk

lib/fs.vk Pure-Veko ergonomic filesystem utilities built over the Phase 3A OS PAL (os/*), path, and glob. Provides exists?, dir?, file?, mkdir-all, remove-all, walk-dir, glob-dir, copy-file, write-atomic, and RAII with-temp-dir. Requires .fs capability.

exists? fn caps: .fs
signature
exists? = fn [p str] bool

Returns true if p exists on the filesystem.

dir? fn caps: .fs
signature
dir? = fn [p str] bool

Returns true if p exists and is a directory.

file? fn caps: .fs
signature
file? = fn [p str] bool

Returns true if p exists and is a regular file (not a directory).

mkdir-all fn caps: .fs
signature
mkdir-all = fn [p str] enum

Recursively creates directory p and all missing parent directories (idempotent).

Executable Example
veko
use [fs]
base = str/join [(os/temp-dir) '/veko_fs_dt_mkdir'] ''
_ = fs/remove-all base
leaf = str/join [base '/a/b/c'] ''
_ = fs/mkdir-all leaf
ok = fs/dir? leaf
_ = fs/remove-all base
if not ok [ err 'mkdir-all' ] else [ .ok ]
remove-all fn caps: .fs
signature
remove-all = fn [p str] enum

Recursively removes a file or directory tree (no-op if p does not exist).

signature
walk-dir = fn [root_dir str] block[str]

Recursively collects all file paths beneath root_dir.

Executable Example
veko
use [fs]
base = str/join [(os/temp-dir) '/veko_fs_dt_walk'] ''
_ = fs/remove-all base
_ = fs/mkdir-all (str/join [base '/sub'] '')
_ = fs/write-atomic (str/join [base '/a.vk'] '') (bytes/from-str 'a')
_ = fs/write-atomic (str/join [base '/sub/b.vk'] '') (bytes/from-str 'b')
found = fs/glob-dir base '*.vk'
_ = fs/remove-all base
if (len found) != 2 [ err 'walk/glob-dir' ] else [ .ok ]
signature
glob-dir = fn [root_dir str, pattern str] block[str]

Recursively collects all file paths beneath root_dir whose basename or relative path matches pattern.

write-atomic fn caps: .fs
signature
write-atomic = fn [dst_path str, data bytes] i64

Atomically writes data to dst_path via a sibling temporary file, os/fsync, and os/rename.

copy-file fn caps: .fs
signature
copy-file = fn [src_path str, dst_path str] i64

Copies src_path to dst_path atomically, returning the number of bytes copied.

with-temp-dir fn caps: .clocks
signature
with-temp-dir = fn [prefix str, work fn[str->any]] any

Creates a unique temporary directory under os/temp-dir, invokes (work dir_path), and removes the directory via defer.

list-entries fn caps: .fs
signature
list-entries = fn [dir_path str] block[map]

Lists entries in dir_path as { name = str, is_dir = bool, size = i64 } maps (ready for ui/widgets/entries-from-list).