util.file.contents

Shared

Retrieves the contents of a specified directory path


Syntax

local contents = util.file.contents(
    path,
    directory_search = false
)

Prefix the path with :resourcename to access directories 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/images accesses the files/images directory inside resource_a.

Parameters

TypeNameDescription
stringpathDirectory path to check for contents
booldirectory_searchIndicates whether to search only for directories, ignoring files

Returns

TypeNameDescription
table | boolcontentsContents of the specified directory on successful execution, false otherwise

Examples

List the contents of a directory within the current resource
core.engine.print("info", "File contents:")
core.engine.iprint(util.file.contents("files/images"))
List the contents of a directory from another running resource
core.engine.print("info", "File contents:")
core.engine.iprint(util.file.contents(":resource_a/files/images"))

On this page