> ## Documentation Index
> Fetch the complete documentation index at: https://docs.squarecloud.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Managing files

> Browse, read, create, move and delete files inside your application through the FilesModule.

Every method on this page lives on `app.files`:

```typescript theme={null}
const app = await api.applications.fetch("abc123def456abc123def456");
app.files; // FilesModule
```

## Listing files in a directory

`app.files.list(path?)` returns the entries of a directory. The path defaults to `"/"`.

```typescript theme={null}
const entries = await app.files.list("/");
console.log(entries);
// [
//   { type: "file",      name: "index.js", size: 123, lastModified: 1717084800000 },
//   { type: "directory", name: "src",      size: 0,   lastModified: 1717084800000 },
// ]
```

## Reading a file

`app.files.read(path)` returns a Node.js `Buffer` with the file contents, or `undefined` when the file is missing.

```typescript theme={null}
const buffer = await app.files.read("/index.js");
console.log(buffer?.toString("utf8"));
```

## Creating or overwriting a file

`app.files.create(file, fileName, path?)` writes a file at `path/fileName`. The path defaults to `"/"`.

| Parameter  | Type               | Description                                            |
| ---------- | ------------------ | ------------------------------------------------------ |
| `file`     | `string \| Buffer` | A local file path or the raw `Buffer` content          |
| `fileName` | `string`           | File name with extension (e.g. `"version.ts"`)         |
| `path`     | `string`           | Absolute directory path inside the app (default `"/"`) |

<Tabs>
  <Tab title="From a Buffer">
    ```typescript theme={null}
    const content = Buffer.from("export default 1\n");
    await app.files.create(content, "version.ts", "/src");
    ```
  </Tab>

  <Tab title="From a local path">
    ```typescript theme={null}
    import { join } from "node:path";

    const localPath = join(__dirname, "version.ts");
    await app.files.create(localPath, "version.ts", "/src");
    ```
  </Tab>
</Tabs>

<Warning>
  The signature changed in v4. Previous versions accepted `create(content, fullPath)` — v4 requires `create(content, fileName, path)`.
</Warning>

## Moving or renaming a file

`app.files.move(path, newPath)` moves or renames a file or directory.

```typescript theme={null}
await app.files.move("/version.ts", "/src/version.ts");
```

## Deleting a file or directory

`app.files.delete(path)` deletes a file or an entire directory.

```typescript theme={null}
await app.files.delete("/src/version.ts");
```
