ilusm.dev

fs

Filesystem access - read and write files, append, list directories, check existence, remove, create directories, find files by substring pattern, get file metadata, and get the current working directory. A thin, stable wrapper over the lower-level io module.

Load with: use fs

What this module does

fs is the everyday filesystem interface for ilusm programs. Every function delegates to io or a __sys_* native. Use fs.rd / fs.wr for simple file I/O, fs.ls to list a directory, and fs.has / fs.ex to check whether a path exists before acting on it.

Quick example

use fs

src = fs.rd("src/main.ilu")
fs.wr("out/main.ilu", src)
fs.app("log.txt", "started\n")

if fs.has("data/"):
    files = fs.ls("data/")

fs.md("dist/assets")
fs.rm("tmp/scratch.txt")

hits = fs.find("src/", ".ilu")
prn(fscwd())

Functions

Read and write

fs.rd(path) / fsrea(path)

Reads and returns the full contents of path as a string.

fs.wr(path, content)

Writes content to path, creating or overwriting.

fsapp(path, content) / fs.app(path, content)

Appends content to an existing file.

Directory and metadata

fsls(dir) / fs.ls(dir)

Returns a list of entry names in dir.

fsmk(dir) / fsmd(dir) / fs.md(dir)

Creates a directory (including parents where supported).

fsmt(path) / fs.fsmt(path)

Returns file metadata via __sys_file_meta.

fscwd() / fs.fscwd()

Returns the current working directory string.

Existence and removal

fshas(path) / fs.has(path)

Returns tru if path exists on the filesystem.

fsex(path) / fs.ex(path)

Returns tru if the path is readable (uses a try around io.rd).

fsrm(path) / fs.rm(path)

Removes the file at path.

Search

fsfind(dir, pattern) / fs.find(dir, pattern)

Lists dir and returns only entries whose names contain pattern as a substring.

Notes

  • All functions delegate to io or __sys_* - no cross-platform abstraction beyond what io provides.
  • Requires io, trl, and txt.