Filesystem

The filesystem functions allow read and write access to a designated folder in the directory of the executor, typically called workspace.


readfile

function readfile(path: string): string

Returns the contents of the file located at path.

Parameters

  • path - The path to the file.

Example

writefile("file.txt", "Hello, world!")
print(readfile("file.txt")) --> Hello, world!

listfiles

function listfiles(path: string): {string}

Returns a list of files and folders in the folder located at path. The returned list contains whole paths.

Parameters

  • path - The path to the folder.

Example

Prints every file and folder in workspace.


writefile

Writes data to the file located at path if it is not a folder.

Parameters

  • path - A path to the file.

  • data - The data to write.

Example


makefolder

Creates a folder at path if it does not already exist.

Parameters

  • path - The target location.

Example


appendfile

Appends data to the end of the file located at path. Creates the file if it does not exist.

Parameters

  • path - A path to the file.

  • data - The data to append.

Example


isfile

Returns whether or not path points to a file.

Parameters

  • path - The path to check.

Example


isfolder

Returns whether or not path points to a folder.

Parameters

  • path - The path to check.

Example


delfile

Removes the file located at path.

Parameters

  • path - The path to the file.

Example


delfolder

Removes the folder located at path.

Parameters

  • path - The path to the folder.

Example


loadfile

Generates a chunk from the file located at path. The environment of the returned function is the global environment.

If there are no compilation errors, the chunk is returned by itself; otherwise, it returns nil plus the error message.

chunkname is used as the chunk name for error messages and debug information. When absent, it defaults to a random string.

Parameters

  • path - A path to the file containing Luau code.

  • chunkname - Optional name of the chunk.

Example


dofile

Attempts to load the file located at path and execute it on a new thread.

🔎 Note

Some executors may provide the file name to the top-level vararg of the file (...).

Parameters

  • path - The path to the file.

Example

Last updated