node.js - 错误:ENOENT:没有这样的文件或目录,即使文件存在也取消链接
问题描述
如您所见,目录存在,文件也存在,但由于某种原因,它无法找到要删除的文件。
代码:
const fs = require('fs')
const path = "./resources/castigos/silencios/705143456384811039/526122991042428959.json"
fs.unlink(path, (err) => {
if (err) {
console.error(err)
return
}
//file removed
})
我尝试以root身份运行该项目,没有...
[Error: ENOENT: no such file or directory, unlink './resources/castigos/silencios/705143456384811039/526122991042428959.json'] {
errno: -2,
code: 'ENOENT',
syscall: 'unlink',
path: './resources/castigos/silencios/705143456384811039/526122991042428959.json'
}
解决方案
In your image file name is different, I believe wrong screen shared,
Also whenever dealing with fs and file paths use path
module and __dirname
you can update your path as below
const path = require('path');
const filePath = path.join(__dirname, '/resources/castigos/silencios/705143456384811039/526122991042428959.json');
推荐阅读
- hive - 列“ex:x 属于字符串类型”的 Parquet 模式不兼容 列类型:STRING、Parquet 模式
- python - 如何将列表列表转换为网格格式的单个字符串?
- python - 找到最大加权子集,使得子集中的任何两个元素总和不等于 k
- azure - 是否可以在工作区上过滤 OMS 仪表板?
- windows - 无法更改服务启动模式
- java - “dev”配置覆盖 Quarkus 中的“test”配置
- ios - Delphi iOs如何检测挂机
- npm - 如何使用 webpack 配置复制 npm 依赖项
- azure - 在 Azure 上的资源组之间移动后删除 microsoft.web/certificates
- java - 调用 glUniformMatrix4fv() 会导致段错误