Filesystem

readfile

Reads the full contents of a file from the executor workspace.

Syntax

readfile(path: string): string
Aliases readfileasync

Arguments

NameTypeDescription
pathstringWorkspace-relative path to the file or folder.

Returns

NameTypeDescription
contentstringFull file contents.

Description

Reads the full contents of a file from the executor workspace.

Call it with 1 parameter(s): path. The argument table explains which values are required and which ones only refine the behavior.

It returns content (string). Use the returns table to separate successful values from nil results and recoverable errors.

Example

Read a workspace file after checking that it exists.

local path = "workspace/examples/config.json"

if isfile(path) then
    local content = readfile(path)
    print(content)
end