File operations are accessed through the global file object.
Returns a path relative to the source file's directory.
let path = file.resolve("data.txt")
Reads the entire contents of a file and returns it as a string. Returns an empty string on error.
let contents = file.read("/etc/hostname")
let contents = file.read(file.resolve("data.txt"))
Writes a string to a file, replacing its contents. Returns true on success.
file.write("/tmp/out.txt", "hello\n")
Appends a string to a file without truncating it. Returns true on success.
file.append("/tmp/log.txt", "another line\n")
Returns true if a file or directory exists at the given path.
if file.exists("/tmp/out.txt"):
print("found it")
Deletes a file. Returns true if the file was removed.
file.remove("/tmp/out.txt")
Creates a directory and any missing parents. Returns true if created.
file.mkdir("/tmp/myapp/data")
Returns the size of a file in bytes, or -1 on error.
let n = file.size("/tmp/out.txt")
Returns a List<String> of filenames (not full paths) in a directory.
let entries = file.listDir("/tmp")