Filesystem
These functions provide a safe interface for file operations within a designated workspace.
appendfile
Appends data to an existing file.
Parameters
path
: The path to the file, relative to the workspacedata
: The string data to append to the file
Example
readfile
Reads the contents of a file.
Parameters
path
: The path to the file, relative to the workspace
Returns
The contents of the file as a string, or nil if the file doesn't exist
Example
local content = readfile("config.txt")
if content then
print("Config contents:", content)
else
print("Config file not found")
end
listfiles
Lists files and directories in the specified directory.
Parameters
path
: The directory path, relative to the workspace
Returns
A table containing the names of files and directories in the specified path
Example
writefile
Writes data to a file, creating it if it doesn't exist or overwriting it if it does.
Parameters
path
: The path to the file, relative to the workspacedata
: The string data to write to the file
Example
makefolder
Creates a new directory.
Parameters
path
: The path of the directory to create, relative to the workspace
Example
isfile
Checks if the specified path is a file.
Parameters
path
: The path to check, relative to the workspace
Returns
true
if the path is a file, false
otherwise
Example
isfolder
Checks if the specified path is a directory.
Parameters
path
: The path to check, relative to the workspace
Returns
true
if the path is a directory, false
otherwise
Example
delfile
Deletes a file.
Parameters
path
: The path of the file to delete, relative to the workspace
Example
delfolder
Deletes a directory and all its contents.
Parameters
path
: The path of the directory to delete, relative to the workspace
Example
Note: All these functions operate within your designated workspace
folder for safety. Paths are relative to this workspace, and operations outside this workspace are not allowed. Certain file extensions and operations may be restricted for security reasons.