wolfhacklua API 1.1 Forum

file

Read and write files in the script's own data folder, and nowhere else.

since 1.0no 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?

Reads a whole file.

ParameterTypeDescription
pathstringA relative path.
ReturnsDescription
string | nilThe file's text.
string?The error when it is nil.
lua
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).

ParameterTypeDescription
pathstringA relative path.
datastringThe text.
ReturnsDescription
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.

ParameterTypeDescription
pathstringA relative path.
datastringText to add.
ReturnsDescription
booleantrue on success.
string?The error on failure.

file.exists#since 1.0

file.exists(path: string): boolean

Checks for a file.

ParameterTypeDescription
pathstringA relative path.
ReturnsDescription
booleanWhether the file exists.

file.remove#since 1.0

file.remove(path: string): boolean

Deletes a file.

ParameterTypeDescription
pathstringA relative path.
ReturnsDescription
booleanWhether a file was removed.

file.list#since 1.0

file.list(dir?: string): string[]

Lists a folder.

ParameterTypeDescription
dir optionalstringA relative folder. default the data folder
ReturnsDescription
string[]File names.

file.usage#since 1.0

file.usage(): integer, integer

How much of the 16 MB / 256 file allowance the script uses.

ReturnsDescription
integerBytes used.
integerNumber of files.
API 1.1 · source docs-src/api/file.json