Skip to content

files

The files namespace provides binary-safe filesystem operations for managing scripts, configs, and assets.


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.

local dir = "aimsense/scripts/data/my_addon"
local file = dir .. "/config.txt"
if not files.exists(dir) then
files.create_folder(dir)
end
-- Write config
files.write(file, "volume=80\nenabled=true")
-- Read back
if files.exists(file) then
local content = files.read(file)
print("Config contents:\n" .. content)
end