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 }Required

The folder to delete: bucket/folder as one string, such as invoices/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.signalAbortSignal

Cancels the call when it aborts. The promise then rejects with aborted.

options.timeoutMsnumber

The longest each request may take, in milliseconds. The client’s timeoutMs when 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.

CodeWhen
validation_failedThe path is wrong. issues names each field, such as path.key
not_foundThe bucket or the folder does not exist. resource says which
folder_not_emptyThe folder still holds files. Delete them first
forbiddenThe 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:

clear-drafts.ts
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