Standard Library

VFS

Filesystem reads, writes, directory walking, globbing, and path manipulation.

vfs is the desktop filesystem module. Import it with use native vfs;. It has no AVR implementation; the Uno has no filesystem.

Reading

FunctionResultNotes
vfs.read(path)String / nullWhole file in binary mode; null on failure.
vfs.read_lines(path)ArrayLines without \n (and without a trailing \r).
vfs.read_bytes(path)ArrayBoxed Int64 bytes, 0..255.
 vyne snippetvyne
use native vfs; text := vfs.read("data/input.csv"); lines := vfs.read_lines("data/input.txt"); bytes := vfs.read_bytes("data/model.bin");

Writing

FunctionResultNotes
vfs.write(path, text)BoolTruncate and write a string; checks write and close results.
vfs.write_atomic(path, text)BoolWrite a private sibling, then replace/create the destination atomically.
vfs.append(path, text)BoolAppend a string.
vfs.write_lines(path, lines)BoolWrite each line followed by \n.
vfs.write_bytes(path, bytes)BoolWrite Int64 bytes masked to 0..255.
 vyne snippetvyne
vfs.write("out.txt", "hello\n"); vfs.append("out.txt", "world\n"); vfs.write_lines("out.txt", ["a", "b", "c"]); if !vfs.write_atomic("scene.vscene", "VMGE_SCENE|1\n") { throw "Scene save failed"; }

write_atomic checks the complete write and fclose before replacing the destination. A temporary-open, write, close, or replacement failure returns false without truncating the destination, and removes its temporary file. POSIX uses mkstemp and rename; Windows uses exclusive sibling creation and MoveFileExA with replacement enabled. Like existing Windows vfs functions, it uses narrow/ANSI paths; file contents remain UTF-8 bytes. Ordinary write can already have changed the destination when it reports a close failure.

Metadata

FunctionResult
vfs.exists(path)Bool
vfs.is_file(path)Bool
vfs.is_dir(path)Bool
vfs.size(path)Int64 bytes; 0 when unavailable
vfs.mtime(path) / vfs.atime(path)Int64 epoch seconds

Directories

FunctionResultNotes
vfs.list_dir(path)ArrayEntry names, . and .. omitted.
vfs.walk(path)ArrayRecursive file list.
vfs.glob(dir, pattern)ArrayGlob match against entry names.
vfs.mkdir(path)BoolCreate one directory.
vfs.mkdir_p(path)BoolCreate a directory tree.
vfs.remove(path)BoolRemove a file.
vfs.remove_dir(path)BoolRemove a directory recursively.
vfs.copy(src, dst)BoolCopy a file.
vfs.move(src, dst)BoolMove or rename. rename is an alias.
 vyne snippetvyne
vfs.mkdir_p("build"); for_name := vfs.glob("data", "*.csv"); vfs.copy("data/input.csv", "build/input.csv");

Path operations

FunctionResult
vfs.basename(path)Last path component
vfs.dirname(path)Parent directory
vfs.stem(path)Filename without extension
vfs.extension(path)Extension including the dot
vfs.join(a, b)Joined path
 vyne snippetvyne
out(vfs.join("data", "train.csv")); # data/train.csv out(vfs.stem("data/train.csv")); # train out(vfs.extension("data/train.csv")); # .csv

Memory and errors

  • vfs.read allocates the file contents in the arena. Inside a region, the string is reclaimed at the closing brace.
  • File-open failures return null (reads) or false (writes), not exceptions. Check the result when the file is required.
  • Paths are UTF-8. Windows separators are handled internally; use / or \ as appropriate.

See also