Open docs
SDK Guide

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.

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

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

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:

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

Folder errors

Errors carry a code to decide on:

CodeMeaning
invalid_nameThe name breaks the rules above.
duplicate_nameA sibling folder already has that name (details["name"]), or the destination already holds a file with that name.
folder_cycleA move into the folder itself or one of its subfolders.
folder_too_deepThe result would be deeper than 64 levels or longer than 1,024 bytes.
folder_not_emptydelete without recursive=True on a folder that holds files or folders.
stale_versionThe folder or file changed since it was read. Read it again before retrying.

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.

Copyright © 2026