space.fs.rmdir()
Delete an empty folder, and any empty folders inside it.
Deletes a folder and any empty folders inside it. The folder must hold no files: delete them first with space.fs.delete().
space.fs.rmdir(
path: string | { bucket: string; key: string },
options?: {
signal?: AbortSignal
timeoutMs?: number
}
): Promise<void>Parameters
pathstring | { bucket, key }The folder to delete:
bucket/folderas one string, such asinvoices/2026/q1, or an object such as{ bucket: "invoices", key: "2026/q1" }.- The bucket is 3 to 63 lowercase letters, digits, and single hyphens, starting and ending with a letter or digit.
- The folder follows the rules for keys: 1 to 1,024 bytes, and it cannot start or end with
/, hold//, have a folder named.or.., or hold control characters.
options.signalAbortSignalCancels the call when it aborts. The promise then rejects with
aborted.options.timeoutMsnumberThe longest each request may take, in milliseconds. The client’s
timeoutMswhen you leave it out, 30,000 by default.
Returns
A promise that resolves with no value once the folder is deleted.
Errors
The promise rejects with a SpaceError. The call never throws before it returns the promise, and when an argument is wrong, nothing is sent.
| Code | When |
|---|---|
validation_failed | The path is wrong. issues names each field, such as path.key |
not_found | The bucket or the folder does not exist. resource says which |
folder_not_empty | The folder still holds files. Delete them first |
forbidden | The API key may not delete files |
Every call can also fail with the codes listed on SpaceError, such as timeout and network_error.
Example
Delete every file in a folder, then the folder:
import { space } from "digitospace"
for await (const entry of space.fs.list("invoices/drafts", { recursive: true })) {
if (entry.type === "file") {
await space.fs.delete({ bucket: "invoices", key: entry.key })
}
}
await space.fs.rmdir("invoices/drafts")Last updated