Skip to content

Filesystem

These functions provide a safe interface for file operations within a designated workspace.


appendfile

function appendfile(path: string, data: string)

Appends data to an existing file.

Parameters

  • path: The path to the file, relative to the workspace
  • data: The string data to append to the file

Example

appendfile("log.txt", "New log entry\n")

readfile

function readfile(path: string): string

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

function listfiles(path: string): table

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

local files = listfiles("data")
for _, file in ipairs(files) do
    print(file)
end

writefile

function writefile(path: string, data: string)

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 workspace
  • data: The string data to write to the file

Example

writefile("output.txt", "Hello, World!")

makefolder

function makefolder(path: string)

Creates a new directory.

Parameters

  • path: The path of the directory to create, relative to the workspace

Example

makefolder("new_directory")

isfile

function isfile(path: string): boolean

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

if isfile("data.txt") then
    print("data.txt is a file")
end

isfolder

function isfolder(path: string): boolean

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

if isfolder("data") then
    print("data is a directory")
end

delfile

function delfile(path: string)

Deletes a file.

Parameters

  • path: The path of the file to delete, relative to the workspace

Example

delfile("old_config.txt")

delfolder

function delfolder(path: string)

Deletes a directory and all its contents.

Parameters

  • path: The path of the directory to delete, relative to the workspace

Example

delfolder("old_data")

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.