Standard Library: Fs
Read and manipulate files and directories
Paths are resolved relative to the current working directory.
Tip: To read files from a fixed path, consider using
import, which which allows you to load and process file
contents from a path relative to a script's source file.
import "text:some-file.txt" -- Import text file as a string
import "raw:some-file.png" -- Import file as a list of bytes
Fs.ls(path)
List the contents of the directory at path.
ls("./school")
Example output:
["classes/", "notes/", "to-do.txt"]
Fs.read(path)
Read the text file at path.
Fs.read("lyrics.txt")
Fs.readBytes(path)
Read the file at path as a list of bytes.
Fs.readBytes("icon.png")
Fs.write(value, path)
Convert value to a string and write to the file at
path, creating the file if it doesn't already
exist. Return the converted string.
Fs.write("I hope you understand, everybody scams", "lyrics.txt")
Fs.writeBytes(bytes, path)
Write a list bytes to the file at path,
creating the file if it doesn't already exist.
bytes must be a list of integers, between
0 and 255, inclusive. Return
bytes.
Fs.writeBytes([72, 101, 108, 108, 111], "greeting.txt")