Skip to content

file

Sandboxed filesystem access confined to the Conduit workspace directory.

file.read(path: string) -> string?, string?

Reads the full contents of a file as a string, returning nil on failure to open, or nil plus an error message if the file exceeds the 64 MiB read limit.

local data = file.read("config.txt")

file.write(path: string, data: string) -> boolean

Overwrites (or creates) a file with the given binary-safe string data, creating parent directories as needed.

file.write("out.txt", "hello")

file.append(path: string, data: string) -> boolean

Appends binary-safe string data to the end of a file, creating it if it does not exist.

file.append("log.txt", "line\n")

file.createfile(path: string) -> boolean

Creates an empty file at the given path if it does not already exist, without truncating an existing one.

file.createfile("marker.txt")

file.mkdir(path: string) -> boolean

Creates a directory, including any missing parent directories.

file.mkdir("saves/profile1")

file.isfile(path: string) -> boolean

Returns true if the path exists and is a regular file.

if file.isfile("config.txt") then end

file.isdir(path: string) -> boolean

Returns true if the path exists and is a directory.

if file.isdir("saves") then end

file.listdirs(path: string) -> table<number, string>

Lists subdirectories directly inside the given directory, as paths relative to the workspace root.

for _, d in ipairs(file.listdirs(".")) do print(d) end

file.listobjects(path: string) -> table<number, string>

Lists all entries (files and directories) directly inside the given directory, as paths relative to the workspace root.

for _, o in ipairs(file.listobjects(".")) do print(o) end

file.listfiles(path: string) -> table<number, string>

Lists regular files directly inside the given directory, as paths relative to the workspace root.

for _, f in ipairs(file.listfiles(".")) do print(f) end