Basics

Files

Reading and writing files in the scripts folder.

files reads and writes files in the scripts folder. Paths are relative to the plugin's own folder, with / between folders. .. reaches other plugins' folders, but nothing outside scripts can be reached: absolute paths, drive letters and : are refused.

Failures return nil, message, like Lua's io, so you can check them:

local data, err = files.read("settings.txt")
if not data then print("no settings yet: " .. err) end

files.write("logs/today.txt", "started\n")
files.append("logs/today.txt", "ticked\n")

local icon = gfx.image_from_png(files.read("icon.png"))
files.read(path)string | nil, message
The file's contents. Any bytes, up to 32 MiB.
files.write(path, data)true | nil, message
Writes the file, replacing it. Missing folders are created.
files.append(path, data)true | nil, message
Adds to the end of the file, creating it if needed.
Whether a file or folder is there.
Whether it's a folder.
files.size(path)integer | nil, message
The file's size in bytes.
files.list([path])string[] | nil, message
The sorted names in a folder; the plugin's own folder by default.
files.mkdir(path)true | nil, message
Creates a folder, and any missing parent folders.
files.remove(path)true | nil, message
Deletes a file.
files.remove_dir(path)true | nil, message
Deletes a folder.
For now the game can't list folders, so files.list returns an error until it can.