Parameters
dirstringThe folder to read, relative to the workspace. Empty — the default — reads the workspace itself.
recursivebooleanfalseWalk 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)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
| Code | Status | When |
|---|---|---|
| path_not_found | 404 | No folder at that path. |
| not_a_folder | 400 | The path names a file. |
| invalid_path | 400 | Absolute, or outside the workspace. |
| local_files_require_node | 400 | The runtime has no filesystem. |
| storage_not_on_this_machine | 409 | Another 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