LocalFiles

list()

files.list(dir?, { recursive? }) → Promise<Item[]>

The contents of a folder: folders first, then files, by name. With recursive, every file of the tree instead.

freehidden entries omitted500 items at most
Using Python?

Switch any code block to Python: the choice applies to every page. Python SDK guide and resource reference.

Parameters

dirstring

The folder to read, relative to the workspace. Empty — the default — reads the workspace itself.

recursivebooleanfalse

Walk the whole tree and return files only, with their full relative paths.

One level

await pc.files.list();
// [
//   { name: "Launch plan", path: "Launch plan", type: "folder", size: null,  mimeType: null,            modifiedAt: "…" },
//   { name: "notes.md",    path: "notes.md",    type: "file",   size: 1284,  mimeType: "text/markdown", modifiedAt: "…" }
// ]

await pc.files.list("Launch plan");
// [ { name: "brief.md", path: "Launch plan/brief.md", type: "file", … } ]
pc.files.list()
# [
#   {"name": "Launch plan", "path": "Launch plan", "type": "folder", "size": 0},
#   {"name": "notes.md",    "path": "notes.md",    "type": "file",   "size": 1284}
# ]

pc.files.list("Launch plan")
# [{"name": "brief.md", "path": "Launch plan/brief.md", "type": "file", …}]

Folders come before files, and each group is sorted by path. That order is stable, so a listing can be shown as it arrives.

The whole tree

recursive: true changes what comes back, not just how deep it goes: folders are no longer entries of their own. You get the files, each one carrying the path you can pass straight to read().

const files = await pc.files.list("", { recursive: true });

// Every file, no folder entries
const markdown = files.filter((f) => f.mimeType === "text/markdown");
const bytes = files.reduce((total, f) => total + f.size, 0);
files = [f for f in pc.files.list("", recursive=True) if f["type"] == "file"]

# Every file, no folder entries
markdown = [f for f in files if f["path"].endswith(".md")]
total_bytes = sum(f["size"] for f in files)
The cap is 500 items, and it is not reported

A walk stops once it has 500 entries. There is no flag saying so, which matters on a large workspace: to work through more than that, list a folder at a time rather than the root recursively.

What is not in the result

Entries whose name begins with a dot are skipped, at every level. Naming one explicitly as dir reads it anyway — that is how the kept versions and the recycle bin stay reachable while staying out of the way.

Errors

CodeStatusWhen
path_not_found404No folder at that path.
not_a_folder400The path names a file.
invalid_path400Absolute, or outside the workspace.
local_files_require_node400The runtime has no filesystem.
storage_not_on_this_machine409Another computer's storage.
import { IaGenifyError } from "iagenify";

async function listOrEmpty(files, dir) {
  try {
    return await files.list(dir);
  } catch (err) {
    if (err instanceof IaGenifyError && err.code === "path_not_found") return [];
    throw err;
  }
}
from iagenify import IaGenifyError

def list_or_empty(files, directory):
    try:
        return files.list(directory)
    except IaGenifyError as error:
        if error.code == "path_not_found":
            return []
        raise