files
The files namespace provides binary-safe filesystem operations for managing scripts, configs, and assets.
Functions
Section titled βFunctionsβ| Function | Parameters | Returns | Description |
|---|---|---|---|
files.read |
path: string |
string |
Reads full file contents (binary-safe). Returns "" and logs error if file is missing. |
files.write |
path: string, data: string |
boolean |
Overwrites or creates file with binary-safe content. |
files.exists |
path: string |
boolean |
Checks if a file or directory exists. |
files.create_folder |
path: string |
boolean |
Creates directory and any missing intermediate parent folders. |
files.list |
path: string |
table |
Returns a sorted, 1-based table of filenames in the directory. |
files.delete |
path: string |
boolean |
Deletes a specified file or empty folder. |
Example: Saving and Reading Config Files
Section titled βExample: Saving and Reading Config Filesβlocal dir = "aimsense/scripts/data/my_addon"local file = dir .. "/config.txt"
if not files.exists(dir) then files.create_folder(dir)end
-- Write configfiles.write(file, "volume=80\nenabled=true")
-- Read backif files.exists(file) then local content = files.read(file) print("Config contents:\n" .. content)end