Docs / API reference / file
file
Read and write files in the script's own data folder, and nowhere else.
since 1.0 no permission needed
Paths are relative to Documents\Base\script-data\<id>\. Forward slashes or backslashes both work. A path with .., a drive letter, a stream colon, a device name (con, nul, ...) or a trailing dot or space is refused. settings.json belongs to the store . Limits: 4 MB per file, 16 MB and 256 files in all. To read files that ship inside the script folder, use assets.read .
Reference# file.read# since 1.0 file .read (path: string): string | nil , string?Parameter Type Description pathstringA relative path.
Returns Description string | nilThe file's text. string?The error when it is nil.
lua Copy
local text, err = file .read ("notes/a.txt" )
if not text then log .warn (err) end file.write# since 1.0 file .write (path: string, data : string): boolean, string?Creates or replaces a file (folders are created as needed).
Parameter Type Description pathstringA relative path. datastringThe text.
Returns Description booleantrue on success.string?The error on failure.
file.append# since 1.0 file .append (path: string, data : string): boolean, string?Adds text to the end of a file.
Parameter Type Description pathstringA relative path. datastringText to add.
Returns Description booleantrue on success.string?The error on failure.
file.exists# since 1.0 file .exists (path: string): booleanParameter Type Description pathstringA relative path.
Returns Description booleanWhether the file exists.
file.remove# since 1.0 file .remove (path: string): booleanParameter Type Description pathstringA relative path.
Returns Description booleanWhether a file was removed.
file.list# since 1.0 file .list (dir?: string): string[]Parameter Type Description dir optional stringA relative folder. default the data folder
Returns Description string[]File names.
file.usage# since 1.0 file .usage (): integer, integerHow much of the 16 MB / 256 file allowance the script uses.
Returns Description integerBytes used. integerNumber of files.
API 1.1 · source docs-src/api/file.json