错误:ENOENT:没有此类文件或目录,请取消链接 [英] Error: ENOENT: no such file or directory, unlink

查看:181
本文介绍了错误:ENOENT:没有此类文件或目录,请取消链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所见,路径中有一个文件.但是fs说没有这样的文件或目录.我不明白为什么?

As you can see, there is a file at the path. But fs says no such file or directory. I can't understand why?

在另一个文件中,我可以使用相同的代码删除.

In another file, I can remove with the same code.

我的boat.js文件:

My boat.js file:

boat.findById(req.params.id,function(err, foundBoat) {
    if(err){
        console.log(err);
    }else{
        foundBoat.boatsFoto.forEach(function(path){
            console.log(typeof(path));
            fs.unlink("../public"+path,function(err){
                if(err) throw err;

                console.log('File deleted!');
            });
        });
    } 
});

这是我的错误:

Error: ENOENT: no such file or directory, unlink '../public/uploads/akingokay/BoatsFoto/1524411110335kiralik-tekne.jpg'
at Error (native)

您可以看到我的文件系统

推荐答案

您可以尝试以下方法吗?

Can you try this instead:

fs.unlink("public"+path,function(err){
            if(err) throw err;

            console.log('File deleted!');
        });

这篇关于错误:ENOENT:没有此类文件或目录,请取消链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆