【发布时间】:2019-02-03 08:37:36
【问题描述】:
我在 node.js 应用程序中使用 fs.rename 时遇到了麻烦。 我已经使用了下面的函数,它可以正常工作。
var fs =require("fs");
var path =require("path")
module.exports= function(oldPath, newPath){
oldPath=path.join(__dirname, "..", "documents", "bka" , oldPath);
newPath=path.join(__dirname, "..", "documents", "bka" , newPath);
fs.rename(oldPath, newPath, (err)=>{if (err) console.log(err)});
}
然后我尝试将该功能用于另一种情况。 oldPath 存在。 newPath 不存在。 如果我不更改 newPath 则不会发生错误。如果我更改它,则会出现以下错误,我不知道为什么:
{ Error: ENOENT: no such file or directory, rename '/home/ubuntu/workspace/documents/bka/7_Wall Street_1/9_Whg_Nr_22/7_bob' -> '/home/ubuntu/workspace/documents/bka/7_Wall Street_1/9_Whg_Nr_221/7_bob' at Error (native) errno: -2, code: 'ENOENT', syscall: 'rename', path: '/home/ubuntu/workspace/documents/bka/7_Wall Street_1/9_Whg_Nr_22/7_bob', dest: '/home/ubuntu/workspace/documents/bka/7_Wall Street_1/9_Whg_Nr_221/7_bob' }
如果你能帮助我,那就太好了。过去我看到其他一些人遇到过类似的问题,但我没有找到任何可以让我理解问题的答案。
谢谢阿米特
【问题讨论】: