Skip to content

fs

A global table of functions: fs.<function>(…).

exists

fs.exists: (path: string) -> boolean

Whether a file or folder is there (false for a path this script may not see).

read_text

fs.read_text: (path: string) -> (string?, string?)

The file as UTF-8 text, or nil and a message.

read_bytes

fs.read_bytes: (path: string) -> (string?, string?)

The file's bytes as a string, or nil and a message.

write_text

fs.write_text: (path: string, text: string) -> (boolean?, string?)

Writes a file (making its folders), or returns nil and a message. A mod can write under user://moddata// only.

write_bytes

fs.write_bytes: (path: string, bytes: string) -> (boolean?, string?)

Writes the bytes of a string to a file, like write_text.

list

fs.list: (directory: string, pattern: string?, recursive: boolean?) -> ({ string }?, string?)

The files in a folder (full paths, sorted) whose names match a pattern with * and ?, and inside its folders with recursive.

list_dirs

fs.list_dirs: (directory: string) -> ({ string }?, string?)

The folders directly in a folder (full paths, sorted).

make_dir

fs.make_dir: (path: string) -> (boolean?, string?)

Makes a folder (and the ones above it).

remove

fs.remove: (path: string) -> (boolean?, string?)

Deletes a file, or a folder with what is in it. Nothing there is fine.