I am getting in trouble then using fs.rename in node.js app. I already use the function below and it works as I would expect it to work.
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)});
}
Then I tried to use the function for another case. oldPath exists. newPath doesn't exists. If I don't change newPath no error occurs. If I change it the error below occurs and I have no idea why:
{ 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' }
would be great if you could help me. I have seen some other people had similar problems in the past but I didn't find any answer that could make me understand the problem.
Thanks amit