filesystem
Provides functions to interact with the local filesystem.
Functions
writefile
filesystem.
writefile
(
path:
string
,
--
The path to the file.
content:
string
|
buffer
--
The content to write to the file.
) →
(
)
Writes content (string or buffer) to a specified file. Creates the file if it does not exist, and overwrites it if it does.
Paths
Paths should ideally be relative to a designated workspace or root directory defined by the executor environment. Absolute paths are restricted.
Errors
Type | Description |
---|---|
Cannot write to file '%s' | The file could not be written to due to permissions or other OS-level issues. |
readfile
filesystem.
readfile
(
path:
string
,
--
The path to the file.
asBuffer:
boolean?
--
If true, return content as a buffer; if false (default), return as a string.
) →
string
|
buffer
--
The content of the file, either as a string or a buffer based on the asBuffer flag.
Reads the content of a specified file, returning it as a string or a buffer.
Errors
Type | Description |
---|---|
Cannot read file '%s' | The file does not exist or cannot be read due to permissions. |
loadfile
filesystem.
loadfile
(
path:
string
--
The path to the Lua file.
) →
(
(
(
...any
)
→
...any
)
|
nil
,
--
The loaded chunk as a function, or nil if loading failed.
string?
--
An error message if loading failed.
)
Loads a Lua chunk from the specified file but does not run it.
Environment
The loaded chunk inherits the environment of the caller.
loadstring
This function behaves similarly to loadstring
but operates on file paths instead of raw strings. Refer to closures.loadstring
for potential compilation settings.
Errors
Type | Description |
---|---|
Cannot read file '%s' | The file does not exist or cannot be read due to permissions. |
dofile
filesystem.
dofile
(
path:
string
--
The path to the Lua file.
) →
...any
--
The values returned by the executed chunk.
Loads and runs a Lua chunk from the specified file.
Environment
The executed chunk inherits the environment of the caller.
Errors
Type | Description |
---|---|
Cannot read file '%s' | The file does not exist or cannot be read due to permissions. |
... | Any runtime error originating from the executed chunk. |
delfile
filesystem.
delfile
(
path:
string
--
The path to the file to delete.
) →
(
)
Deletes a specified file.
Errors
Type | Description |
---|---|
Cannot delete file '%s' | The file does not exist, cannot be deleted due to permissions, or the path isn't a file or other issues. |
appendfile
filesystem.
appendfile
(
path:
string
,
--
The path to the file.
content:
string
|
buffer
--
The content to append to the file.
) →
(
)
Appends content (string or buffer) to the end of a specified file. Creates the file if it does not exist.
Errors
Type | Description |
---|---|
Cannot append to file '%s' | The file could not be appended to due to permissions or other OS-level issues. |
movefile
filesystem.
movefile
(
oldpath:
string
,
--
The current path of the file.
newpath:
string
--
The desired new path for the file.
) →
(
)
Moves or renames a file. Does not work on folders.
Behavior
If newpath
already exists, it will overwrite it. Use movefolder
for directories.
Errors
Type | Description |
---|---|
Cannot move file from '%s' to '%s' | Failed due to permissions, item not found, `oldpath` is a folder, target path invalid, or other OS issues. |
movefolder
filesystem.
movefolder
(
oldpath:
string
,
--
The current path of the folder.
newpath:
string
--
The desired new path for the folder.
) →
(
)
Moves or renames a folder. Does not work on files.
Behavior
If newpath
already exists, it will overwrite it. Use movefile
for files.
Errors
Type | Description |
---|---|
Cannot move folder from '%s' to '%s' | Failed due to permissions, item not found, `oldpath` is a file, target path invalid, or other OS issues. |
copyfile
filesystem.
copyfile
(
sourcepath:
string
,
--
The path of the file to copy.
destinationpath:
string
--
The path where the copy should be created.
) →
(
)
Copies a file.
Behavior
If destinationpath
already exists, it will likely be overwritten. This function typically only works for files. For copying folders, use copyfolder
.
Errors
Type | Description |
---|---|
Cannot copy file from '%s' to '%s' | Failed due to permissions, source not found, destination path invalid, or other OS issues. |
copyfolder
filesystem.
copyfolder
(
sourcepath:
string
,
--
The path of the folder to copy.
destinationpath:
string
--
The path where the copied folder should be created.
) →
(
)
Recursively copies a folder and its contents.
Behavior
If destinationpath
already exists as a folder, the contents of sourcepath
might be merged into it, or it might error, depending on implementation. If destinationpath
exists as a file, it will error. This function recursively copies all subfolders and files. Use copyfile
for single files.
Errors
Type | Description |
---|---|
Cannot copy folder from '%s' to '%s' | Failed due to permissions, source not found, `sourcepath` is a file, destination path invalid, or other OS issues during recursion. |
listfiles
filesystem.
listfiles
(
path:
string
,
--
The path to the directory.
options:
ListfilesOptions?
--
A table containing options like Recursive
(boolean, default false) and Hidden
(boolean, default true).
) →
{
string
}
--
A list of names (or relative paths if recursive) of files and folders within the directory.
Lists all files and folders within a specified directory path according to the provided options.
Errors
Type | Description |
---|---|
Cannot list directory '%s' | The directory does not exist or cannot be accessed. |
isfile
filesystem.
isfile
(
path:
string
--
The path to check.
) →
boolean
--
True if the path points to an existing file, false otherwise.
Checks if a given path points to an existing file.
isfolder
filesystem.
isfolder
(
path:
string
--
The path to check.
) →
boolean
--
True if the path points to an existing folder, false otherwise.
Checks if a given path points to an existing folder (directory).
makefolder
filesystem.
makefolder
(
path:
string
--
The path where the folder should be created.
) →
(
)
Creates a new folder (directory) at the specified path.
Errors
Type | Description |
---|---|
Cannot create folder '%s' | The folder could not be created (e.g., path already exists as a file, permissions issue, invalid path). |
delfolder
filesystem.
delfolder
(
path:
string
--
The path to the folder to delete.
) →
(
)
Deletes a specified folder (directory) and all of its contents recursively.
Behavior
This function permanently deletes the specified folder and all files and subfolders within it. Use with caution.
Errors
Type | Description |
---|---|
Cannot delete folder '%s' | The folder does not exist, cannot be deleted due to permissions, or the path isn't a folder or other issues (e.g., a file within is locked). |
getproperties
filesystem.
getproperties
(
path:
string
--
The path to the file or folder.
) →
ItemProperties?
--
A table containing properties (size, creation time, last modified time, hidden, read-only), or nil if the path does not exist. Size will always be 0
for folders.
Retrieves properties of a specified file or folder.
Errors
Type | Description |
---|---|
Cannot get properties for '%s' | Permissions error or other OS issue preventing access. |
setproperties
filesystem.
setproperties
(
path:
string
,
--
The path to the file or folder.
properties:
ItemProperties
--
A table containing the properties to set. Only IsHidden
and IsReadOnly
are typically settable for both files and folders. Other properties in the table are ignored.
) →
(
)
Sets modifiable properties of a specified file or folder.
Settable Properties
Generally, only the IsHidden
and IsReadOnly
flags can be reliably modified. Timestamps and size are usually managed by the OS. The function should ideally ignore attempts to set read-only properties specified in the input table. The effect of IsReadOnly
on folders may vary by OS.
Errors
Type | Description |
---|---|
Cannot set properties for '%s' | The path does not exist, permissions error, or property modification failed. |
getcustomasset
filesystem.
getcustomasset
(
path:
string
--
The path to the local asset file.
) →
string
--
A Roblox asset URL (e.g., rbxasset://some_generated_identifier
).
Takes a path to a local file (e.g., an image) and returns a Roblox content URL (e.g., rbxasset://<filehash>
) that can be used to load the asset within Roblox interfaces.
Usage
This function allows importing local files (like images, sounds, etc.) for use in Roblox UIs or parts by converting them into a temporary or cached asset URL recognized by the engine. The underlying mechanism might involve hashing the file content or uploading it to a temporary storage accessible by the client.
Errors
Type | Description |
---|---|
Cannot process asset '%s' | The file does not exist or could not be processed. |