本页还没有译文
本页 6 段还没译成简体中文,下面显示的是英文原文。Delete directories
还没翻译译自英文(bun.com)本页 6 段都还没译
To recursively delete a directory and all its contents, use rm from node:fs/promises. This is like running rm -rf in JavaScript.
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 contentsforce: true- Don't throw errors if the directory doesn't exist
Omit force to get an error if the directory doesn't exist:
try {
await rm("path/to/directory", { recursive: true });
} catch (error) {
if (error.code === "ENOENT") {
console.log("Directory doesn't exist");
} else {
throw error;
}
}See File I/O for more filesystem operations.
AI 翻译查看英文原文