---
title: "Work with folders"
description: "Create folder trees, move and rename folders and files, and delete a folder with everything in it."
canonical_url: "https://docs.flashdrive.space/sdk/folders"
---
# Work with folders

> Create folder trees, move and rename folders and files, and delete a folder with everything in it.

These examples use the latest stable release of the Python SDK.

`client.folders` manages a drive's folders, which work like folders on a laptop: they nest up to 64 levels deep, and moving or renaming a folder keeps every file in it in place, with each file's `path` following. Every call takes `drive_id` (default: the client's drive, then the workspace default). The async client has the same calls; `await` each one.

```python
from flashdrive import Flashdrive

with Flashdrive() as client:
    made = client.folders.ensure(["reports/2026/q3", "reports/2026/q4"])
    q3 = made[0].id
    client.folders.move(q3, None, name="third-quarter")   # to the top level, renamed
    for folder in client.folders.list():
        print(folder.name, folder.id)
    deletion = client.folders.delete(q3, recursive=True)  # the folder and everything in it
    print(deletion.documents_deleted, deletion.state)
```

## Folder calls

<table>
<thead>
  <tr>
    <th>
      Call
    </th>
    
    <th>
      Result
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        folders.list(parent_folder_id=None)
      </code>
    </td>
    
    <td>
      The direct child folders of <code>
        parent_folder_id
      </code>
      
      , or of the top of the drive.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.get(folder_id)
      </code>
    </td>
    
    <td>
      A <code>
        Folder
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.create(name, parent_folder_id=None)
      </code>
    </td>
    
    <td>
      The new <code>
        Folder
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.rename(folder_id, name)
      </code>
    </td>
    
    <td>
      The renamed <code>
        Folder
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.move(folder_id, parent_folder_id, name=None)
      </code>
    </td>
    
    <td>
      The moved <code>
        Folder
      </code>
      
      , with its files and subfolders. <code>
        None
      </code>
      
       moves it to the top of the drive; <code>
        name
      </code>
      
       also renames it.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.ensure(paths)
      </code>
    </td>
    
    <td>
      A <code>
        FolderPath
      </code>
      
       (<code>
        path
      </code>
      
       and <code>
        id
      </code>
      
      ) for each of up to 500 paths such as <code>
        "reports/2026/q3"
      </code>
      
      . Folders that exist are reused, missing ones are created.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.delete(folder_id)
      </code>
    </td>
    
    <td>
      Deletes an empty folder and returns <code>
        None
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.delete(folder_id, recursive=True, wait=True)
      </code>
    </td>
    
    <td>
      Deletes the folder and everything in it, and returns a <code>
        FolderDeletion
      </code>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folders.continue_deletion(deletion, wait=True)
      </code>
    </td>
    
    <td>
      Carries on a recursive deletion that has not finished.
    </td>
  </tr>
</tbody>
</table>

A `Folder` has `id`, `name`, `parent_folder_id`, `version`, `path`, `depth`, `created_at` and `etag`.

## Name folders

A folder name is 1 to 120 characters after trimming, never `.` or `..`, and has no `/` or control characters. A whole folder path is at most 1,024 bytes. Two folders in the same parent cannot have the same name.

## Delete a folder with everything in it

`folders.delete(folder_id, recursive=True)` removes the folder and all the folders and files inside it. The folders disappear at once and the files are deleted in steps.

- With `wait=True` (the default), the call steps through the deletion until it finishes, for up to `timeout` (default 600 seconds).
- With `wait=False`, it returns the started `FolderDeletion`; pass it to `folders.continue_deletion(deletion)` to carry on.

A `FolderDeletion` has `operation_id`, `state` (`running` or `finished`), `folders_total`, `documents_total` and `documents_deleted`. If a file changes under a step, the SDK starts that step again. If a step still fails after three retries, the call raises the error; carry on later with `folders.continue_deletion(deletion)` and the `FolderDeletion` the first call returned.

## Move and rename files

Files move and rename through `client.documents`. Both calls need the `latest_revision` you read, so they never undo someone else's change:

```python
doc = client.documents.get(document_id)
receipt = client.documents.move(document_id, folder_id, expected_revision=doc.latest_revision)   # None: the top of the drive

doc = client.documents.get(document_id)
client.documents.rename(document_id, "report.txt", expected_revision=doc.latest_revision)
```

Both return a `MutationReceipt` with an `operation_id` you can follow with `client.operations.get(receipt.operation_id)`. The file keeps its ID and `external_id`. A file name is 1 to 255 bytes, not `.` or `..`, with no `/`, backslash or control characters. If the file changed since your read, the call raises `stale_version`; see [replace files](https://docs.flashdrive.space/sdk/replace-and-label) for revision checks.

## Upload into folders

Pass `folder_id` to `client.upload()`. To copy a local folder tree, `ensure` its directory paths, then upload each directory's files with its folder ID, as shown in [upload a large collection](https://docs.flashdrive.space/sdk/bulk-imports).

## Folder errors

Errors carry a `code` to decide on:

<table>
<thead>
  <tr>
    <th>
      Code
    </th>
    
    <th>
      Meaning
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <code>
        invalid_name
      </code>
    </td>
    
    <td>
      The name breaks the rules above.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        duplicate_name
      </code>
    </td>
    
    <td>
      A sibling folder already has that name (<code>
        details["name"]
      </code>
      
      ), or the destination already holds a file with that name.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_cycle
      </code>
    </td>
    
    <td>
      A move into the folder itself or one of its subfolders.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_too_deep
      </code>
    </td>
    
    <td>
      The result would be deeper than 64 levels or longer than 1,024 bytes.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        folder_not_empty
      </code>
    </td>
    
    <td>
      <code>
        delete
      </code>
      
       without <code>
        recursive=True
      </code>
      
       on a folder that holds files or folders.
    </td>
  </tr>
  
  <tr>
    <td>
      <code>
        stale_version
      </code>
    </td>
    
    <td>
      The folder or file changed since it was read. Read it again before retrying.
    </td>
  </tr>
</tbody>
</table>

Every call also takes `timeout` and, for changes, `idempotency_key`. `folders.ensure` refuses more than 500 paths before sending anything, and the service also limits one call to 5,000 folder names in all.


## Sitemap

See the full [sitemap](https://docs.flashdrive.space/sitemap.md) for all pages.
