# list()

Canonical URL: https://developers.iagenify.com/sdk/ref/local-files/list/
Language: en

`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.

Status: free · hidden entries omitted · 500 items at most

## Parameters {#parameters}

| Name | Type | Requirement | Description |
| --- | --- | --- | --- |
| `dir` | string |  | The folder to read, relative to the workspace. Empty — the default — reads the workspace itself. |
| `recursive` | boolean | false | Walk the whole tree and return **files only**, with their full relative paths. |

## One level {#flat}

```javascript
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", … } ]
```

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}

`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()`.

```javascript
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);
```

> **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 {#hidden}

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 {#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. |

```javascript
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;
  }
}
```

- [read()](/sdk/ref/local-files/read): Read one of the files you just listed.
- [LocalFiles](/sdk/ref/local-files): The workspace, the path rules, and the shape every method returns.

```python
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", …}]
```

```python
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)
```

```python
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
```
