# Delete a directory (folder)
Source: https://docs.file.ai/api-reference/folders/delete-a-directory-folder

> Delete a directory and every subfolder beneath it, at any depth.

delete /prod/v1/directories/{directoryId}

Delete a directory and every subfolder beneath it, at any depth.

Files are NOT deleted. Each file is detached from the deleted directories and stays in the workspace and in any other directory it belongs to. To delete files, use `DELETE /v1/files`.

**Path Parameters:**
- `directoryId` (required): The directory to delete. Any depth is accepted — root, subfolder, or deeper.

**Response:**
- `directoryId`: the directory you asked to delete
- `deletedDirectoryIds`: every directory removed, the target first and then its subfolders
- `failedDirectoryIds`: empty on a complete delete

**Notes:**
- The delete is not reversible through the API.
- A directory that has a workflow, contains one at any depth, or is the immediate subfolder of one, is rejected with a 422. Tearing a workflow down is not supported yet.
- The Reference Hub is platform storage and cannot be deleted.
- At most 1000 directories (the target plus its subfolders) are deleted in one request. A bigger tree is rejected with a 422 before anything is deleted; delete its deeper subfolders first.
- A folder in the tree that holds a workflow result file is rejected with a 422 naming the folder ids, before anything is deleted. Remove or move those files first.
- If a directory fails to delete part-way the response is still a 200, with the failures in `failedDirectoryIds` and everything already gone in `deletedDirectoryIds`. The delete stops there, so the target and anything above the failure are still present, and nothing is rolled back. Retry the same call to finish — a partial result is never cached, so retrying under the same `Idempotency-Key` re-runs the delete rather than replaying the partial response.
- If nothing could be deleted at all the response is a 500, not a 200: no directory changed, and the same `Idempotency-Key` stays usable for the retry.
- A second call for the same id is a 404, since the directory no longer exists.
