Built-in file.* and
json.* helpers. Paths are relative to the
process working directory — no
.., no absolute paths.
os.getcwd() only.FileNotFoundError; other OS failures raise IOError.error.try / error.except.file.write(text, path) — truncate and write.file.append(text, path) — append (inserts a newline before text if the file is non-empty).file.read(path) — entire file as one string.file.readline(path) — next line (strips endings); "" at EOF. Keeps a lazy handle until file.close / rewrite.file.close(path) — close the readline handle.file.exists(path) / isfile / isdir — 1 or 0.file.size(path) — byte size.file.listdir(subdir?) — sorted name list (default ".").file.join(a, b, …) — join relative segments with / (still sandboxed).file.rename(old, new) / file.delete(path) / file.mkdir(path).json.read(path) — parse into SPL hash/list tree.json.write(value, path) — serialize (same sandbox).file.mkdir("tmp_demo");
p.setVar(file.join("tmp_demo", "note.txt"));
file.write("hello", p);
print.number(file.exists(p));
print.string(file.read(p));
names.setVar(file.listdir("tmp_demo"));
print.list(names);
Example: examples/file_io_demo.spl