Skip to content

pyio.list_folder

Daniel Flassig edited this page Jul 7, 2026 · 1 revision

Enumerates the contents of a directory

pyio.list_folder(directory, type, pattern, max)
directory:list_folder(type, pattern, max)
Parameter Type Description
directory path handle A path handle that refers to a directory
type string (optional) Filters the result. One of "all" (default), "files" or "folders".
pattern string (optional) A wildcard pattern to filter the name / extension, e.g. "*.txt". When omitted, all entries are returned
max integer (optional) An upper bound on how many directory entries are examined (default 10000). Guards against extremely large directories.

Return values

Type Description
{ (table)* } An array of entries, sorted by name for easy display.
boolean true if the whole directory was enumerated, false if the listing was truncated because max entries were reached.

Each entry is a table with the following keys:

Key Type Description
name string The file or folder name
is_folder boolean true if the entry is a sub-folder
is_hidden boolean true if the entry has the hidden attribute
file_size integer Size in bytes (0 for directories)
last_modified integer Last-modified time as a Lua/Unix timestamp (seconds since 1970-01-01 UTC), compatible with os.date

Example:

local library = pyux.get_library_handle("library")
local entries, complete = pyio.list_folder(library, "files", "*.pyo")
for _, entry in ipairs(entries) do
	pyui.alert(entry.name .. " (" .. entry.file_size .. " bytes, " .. os.date("%Y-%m-%d", entry.last_modified) .. ")")
end
if not complete then
	pyui.alert("Listing was truncated; raise the max argument to see more.")
end

Remarks:

The handle must grant directory access (see Access levels). Calling list_folder on a file handle raises an error, and a non-recursive directory handle never reports sub-folders — so type == "folders" returns an empty array for such a handle.

Version Support:

Minimum PYTHA Version: V26

See also:

pyio, Path Handles, pyio.append_path, get_library_handle

Clone this wiki locally