Replace old docs with new docs repo (#24201)

This commit is contained in:
Lydia Hallie
2025-11-05 11:14:21 -08:00
committed by GitHub
parent 550522e99b
commit 1606a9f24e
407 changed files with 21970 additions and 17527 deletions

View File

@@ -0,0 +1,39 @@
---
title: Delete directories
sidebarTitle: Delete directories
mode: center
---
To recursively delete a directory and all its contents, use `rm` from `node:fs/promises`. This is like running `rm -rf` in JavaScript.
```ts delete-directory.ts icon="/icons/typescript.svg"
import { rm } from "node:fs/promises";
// Delete a directory and all its contents
await rm("path/to/directory", { recursive: true, force: true });
```
---
These options configure the deletion behavior:
- `recursive: true` - Delete subdirectories and their contents
- `force: true` - Don't throw errors if the directory doesn't exist
You can also use it without `force` to ensure the directory exists:
```ts delete-directory.ts icon="/icons/typescript.svg"
try {
await rm("path/to/directory", { recursive: true });
} catch (error) {
if (error.code === "ENOENT") {
console.log("Directory doesn't exist");
} else {
throw error;
}
}
```
---
See [Docs > API > FileSystem](https://bun.com/docs/api/file-io) for more filesystem operations.