I have the following code that is trying to delete a file on a Windows 7 machine:
var imageFullPathName = __dirname + "/../public/images/" + req.params.itemId;
logger.log("imageFullPathName = " + imageFullPathName);
var normalizedPathName = path.normalize(imageFullPathName);
logger.log("normalizedPathName = " + normalizedPathName);
fs.exists(normalizedPathName, function(exists) {
console.log("Found the file: " + normalizedPathName);
normalizedPathName = normalizedPathName.replace(/\\/g,"\\\\");
console.log("New path name = " + normalizedPathName);
fs.unlink(normalizedPathName, function(err){
if (err){
console.error("Error in call to fs.unlink");
}
});
});
I get the following output:
imageFullPathName = C: \ IronKey \ HES \ cscie-71 \ Project \ medical interchange \ routes /../ public / images / 5658e5612103cb2c41000006
normalizedPathName = C: \ IronKey \ HES \ cscie-71 \ Project \ medical interchange \ Public \ images \ 5658e5612103cb2c41000006
New path name = C: \\ IronKey \\\\ HES cscie-71 \\ Project \\ medical-interchange \\\\ public images \\ 5658e5612103cb2c41000006
Error calling fs.unlink
, DOS. , , . , normalizedPathName.replace(), . , ββ, :
fs.unlink( "C:\\IronKey\\\\ HES cscie-71\\\\-\\\\ \\5658e5612103cb2c41000006", function (err) {...
, ? .
josh3736 , ENOENT. , , EXACT , :
var imageFullPathName = path.join(__dirname, "../public/images",
sanitize(req.params.itemId));
logger.log("imageFullPathName = " + imageFullPathName);
fs.unlink(imageFullPathName, function(err){
if (err){
logger.log("Error in call to fs.unlink", err);
}
else{
logger.log("No file found");
}
logger.log("Delete Success");
});
:
fs.unlink {[: ENOENT: , C:\\IronKey\\hes\\cscie-71\\project\\medical-interchange\\public\\images\\5658fd27fca1b3bc3d00000e ']