Skip to content

std/fs

import "std/fs" as fs;

Operations that can fail return T!fs.FsError. Handle them with ?, or, or or err.

FunctionResult
exists(path) BoolWhether any entry exists
isFile(path) BoolWhether the path is a regular file
isDir(path) BoolWhether the path is a directory
mkdir(path) Void!FsErrorCreates one directory
mkdirAll(path) Void!FsErrorCreates missing parent directories
ensureDir(path) Void!FsErrorEnsures a directory exists
readFile(path) String!FsErrorReads the complete file
writeFile(path, content) Void!FsErrorReplaces the complete file
writeFileSafe(path, content) Void!FsErrorCreates parent directories, then writes
touch(path) Void!FsErrorCreates an empty file if absent
remove(path) Void!FsErrorRemoves a file or empty directory
rename(from, to) Void!FsErrorRenames an entry
move(from, to) Void!FsErrorCreates destination parents, then renames
copyFile(from, to) Void!FsErrorCopies a file and creates destination parents
readLines(path) List<String>!FsErrorReads lines without newline characters
writeLines(path, lines) Void!FsErrorWrites a list joined with newlines
import "std/fs" as fs;
fun saveReport(path: String, text: String) Void!fs.FsError {
fs.writeFileSafe(path, text)?;
return;
}
fun main() Int {
saveReport("out/report.txt", "ready") or err {
eprintln("could not save report");
return 1;
};
return 0;
}

FsError variants are PermissionDenied, NotFound, AlreadyExists, NotDirectory, IsDirectory, InvalidPath, OutOfMemory, and Io.