執行環境套件管理器打包器測試執行器程式碼檢查格式化指南參考部落格意見回饋

檢查檔案是否存在

Bun.file() 函式接受一個路徑並傳回一個 BunFile 例項。使用 .exists() 方法可以檢查給定路徑下的檔案是否存在。

index.ts
const path = "/path/to/package.json";
const file = Bun.file(path);

await file.exists(); // 布林值;

請參閱檔案 I/O,瞭解有關使用 BunFile 的更多資訊。