files
Sandboxed file I/O in <xhook folder>\scripts\data\<script>\, one folder per script.
Functions
files.read
files.read(name) -> string | nil| Name | Type | Description |
|---|---|---|
| name | string | Relative 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| Name | Type | Description |
|---|---|---|
| name | string | Relative path. |
| data | string | Bytes; numbers become strings. |
Creates or overwrites a file, making parent folders.
Returns true on success
files.exists
files.exists(name) -> boolean| Name | Type | Description |
|---|---|---|
| name | string | Relative path. |
true if a file or folder exists there.
files.delete
files.delete(name)| Name | Type | Description |
|---|---|---|
| name | string | Relative file path. |
Deletes a file; folders are left alone.
Returns nothing; check with files.exists.
files.mkdir
files.mkdir(dir) -> boolean| Name | Type | Description |
|---|---|---|
| dir | string | Relative folder path. |
Creates a folder and missing parents.
Returns true if the folder exists after
files.list
files.list(dir) -> table[]| Name | Type | Description |
|---|---|---|
| dir | string | "." 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() -> stringFolder name every files.* call is scoped to.
Returns "" outside a script
Fields
files.list() entry
| Name | Type | Description |
|---|---|---|
| name | string | Entry name, no folder part. |
| dir | boolean | true for a folder. |
| size | integer | Bytes. |
| mtime | number | Raw write time, not a Unix timestamp. |