util.file.read

Shared

Reads the content of a specified file


Syntax

local content = util.file.read(
    path
)

Prefix the path with :resourcename to access files from another running resource.

  • Local path — resolves relative to the current resource's directory.
  • Cross-resource path — prefix with :resourcename to resolve relative to another running resource's directory.
  • Example:resource_a/files/data.json accesses files/data.json inside resource_a.

Parameters

TypeNameDescription
stringpathFile path to read

Returns

TypeNameDescription
string | boolcontentFile's content on successful execution, false otherwise

Examples

Read a file within the current resource
core.engine.print("info", "File content:", util.file.read("files/data.json"))
Read a file from another running resource
core.engine.print("info", "File content:", util.file.read(":resource_a/files/data.json"))

On this page