fs
lib/fs.vklib/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.
mkdir-all = fn [p str] enum
Recursively creates directory p and all missing parent directories (idempotent).
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 [p str] enum
Recursively removes a file or directory tree (no-op if p does not exist).
walk-dir = fn [root_dir str] block[str]
Recursively collects all file paths beneath root_dir.
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 ]
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 [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 [src_path str, dst_path str] i64
Copies src_path to dst_path atomically, returning the number of bytes copied.
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 [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).