DirkScripts
Docs
File
βΉοΈ Server Module - This can only be used on the server
#lib.file.load
Load a JSON file and parse it into a table.
lualocal data = lib.file.load('data/config.json') local data = lib.file.load('data/config.json', true) -- from calling resource
| Parameter | Type | Required | Description |
|---|---|---|---|
| path | string | yes | File path relative to the resource |
| from_central | boolean | no | If true, loads from the calling resource instead of dirk_lib |
Returns the parsed table, or false if the file doesn't exist.
#lib.file.save
Save a table as a JSON file.
lualib.file.save('data/config.json', myData) lib.file.save('data/config.json', myData, true) -- to calling resource
| Parameter | Type | Required | Description |
|---|---|---|---|
| path | string | yes | File path |
| data | table | yes | Data to serialise |
| from_central | boolean | no | If true, saves to the calling resource |
Returns true on success.
#lib.file.inDirectory
List files matching a pattern in a directory.
lualocal files, count = lib.file.inDirectory('data/', '*.json')
| Parameter | Type | Required | Description |
|---|---|---|---|
| path | string | yes | Directory path |
| pattern | string | yes | File pattern to match |
