What is the best way to delete several files in node.js?
function deleteFiles(files, callback){
...
}
var files = [\'file1.js\', \'file2.jpg\', \'file3.css\
This deletes the files in an array and runs the callback once only after all files have been deleted.
function deleteFiles(files, callback){
if (files.length==0) callback();
else {
var f = files.pop();
fs.unlink(f, function(err){
if (err) callback(err);
else {
console.log(f + ' deleted.');
deleteFiles(files, callback);
}
});
}
}