Filesystem

isfile

Returns whether a path resolved inside the workspace exists and is a regular file.

Syntax

isfile(path: string): boolean

Arguments

NameTypeDescription
pathstringPath resolved inside the workspace after separator normalization and workspace-boundary checks. Invalid or outside-workspace paths error before a boolean is returned.

Returns

NameTypeDescription
isFilebooleanTrue only when the resolved path exists and is a regular file; folders and missing paths return false.

Description

Returns whether a path resolved inside the workspace exists and is a regular file.

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

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

Example

Check whether a workspace path resolves to an existing regular file.

local folderPath = "examples"
local filePath = "examples/config.json"

makefolder(folderPath)
writefile(filePath, "{}")

print(isfile(filePath))
print(isfile(folderPath))
print(isfile("examples/missing.json"))