node.js - Unable to delete directory using node.js
问题描述
I am trying to delete directory using fs
module from node.js but as per my current code its throwing the following error.
Error:
Error:: { Error: ENOTEMPTY: directory not empty, rmdir '/app/uploads'
at Object.rmdirSync (fs.js:684:3)
at Object.usecaseWorkflow (/app/controller/usecaseWorkflowCtrl.js:97:32)
at process._tickCallback (internal/process/next_tick.js:68:7)
errno: -39,
syscall: 'rmdir',
code: 'ENOTEMPTY',
path: '/app/uploads' }
I am explaining my code below.
if (fs.existsSync(`${process.env['root_dir']}/uploads`)) {
fs.rmdirSync(`${process.env['root_dir']}/uploads`, {
recursive: true,
});
}
Here I am trying to delete uploads
directory present inside root directory but getting that error and also unable to delete. I am using node.js version 10
. Can anybody help me to resolve this issue so that I can delete the directory successfully ?
解决方案
只需使用 node.jsrimraf
递归删除文件。
var rimraf = require("rimraf");
rimraf("/some/directory", function () { console.log("done"); });
推荐阅读
- java - Grails/GORM 动态查找器通过其关系 ID 而不是关系对象本身获取域
- ios - iPhone XR 和 iPhone XS 的 Peek and Pop
- autodesk-forge - Autodesk 的 adsk-icon-* 类
- android - Places.GeoDataApi setResultCallback 不起作用
- powerbi - 拥有 Power Bi Premium 时的 Power Bi Report 服务器许可证
- html - 使方形 div 与右上角对齐,负 50 像素且响应式
- c - 如何在不知道包含文件的情况下编译 C 程序
- xamarin.forms - 当应用程序为后台时,IOS 应用程序中的本地通知
- internationalization - SailsJS i18n 模块即使更改了语言环境也不会更改语言文件
- ansible - 通过 Ansible 创建 Azure Keyvault 机密