【发布时间】:2021-07-12 16:44:06
【问题描述】:
我可以删除所有图像文件(.png、.jpg 等...),但不能删除文件夹...
这是我的代码博客:
router.post('/remove-file', async (req, res) => {
const removeDocuments = await req.body.removeDocuments
// removeDocuments[0] equals to '/assets/img/folder'
// removeDocuments[1] equals to '/assets/img/image.jpg'
if(removeDocuments){
for (let i = 0; i < removeDocuments.length; i++) {
fs.unlinkSync('.' + removeDocuments[i])
}
res.send({
status: true
})
}
})
我得到的错误代码:
(node:808) UnhandledPromiseRejectionWarning: Error: EPERM: operation not permitted, unlink './assets/img/folder'
我的问题出在哪里?如何解决?
【问题讨论】:
标签: javascript node.js ajax fs