xhookLua
Game

files

Sandboxed file I/O in <xhook folder>\scripts\data\<script>\, one folder per script.

Functions

files.read

files.read(name) -> string | nil
NameTypeDescription
namestringRelative path, like "cache/maps.json".

Reads an entire file, binary-safe.

Returns nil if missing or rejected

Paths with "..", ":" or a leading slash are rejected.

files.write

files.write(name, data) -> boolean
NameTypeDescription
namestringRelative path.
datastringBytes; numbers become strings.

Creates or overwrites a file, making parent folders.

Returns true on success

files.exists

files.exists(name) -> boolean
NameTypeDescription
namestringRelative path.

true if a file or folder exists there.

files.delete

files.delete(name)
NameTypeDescription
namestringRelative file path.

Deletes a file; folders are left alone.

Returns nothing; check with files.exists.

files.mkdir

files.mkdir(dir) -> boolean
NameTypeDescription
dirstringRelative folder path.

Creates a folder and missing parents.

Returns true if the folder exists after

files.list

files.list(dir) -> table[]
NameTypeDescription
dirstring"." is the root; "" is rejected.

Lists one folder, not recursive.

Returns entries; empty if missing or rejected

Stops at 8192 entries.

files.script_dir

files.script_dir() -> string

Folder name every files.* call is scoped to.

Returns "" outside a script

Fields

files.list() entry

NameTypeDescription
namestringEntry name, no folder part.
dirbooleantrue for a folder.
sizeintegerBytes.
mtimenumberRaw write time, not a Unix timestamp.
files ยท Lua API ยท xhook