Reputation: 434
I am using angular 6. I want to delete multiple files from backend folder for that, I am using fs.removeSync()
but it gives below exception for me.
can someone help me?
"UnhandledPromiseRejectionWarning: TypeError: fs.removeSync is not a function "
My Code:
fs.removeSync('/NodeWorkspace/uploads/output/*.csv');
Upvotes: 3
Views: 10746
Reputation: 87
fs.removeSync(path)
is a function of fs-extra library which is a wrapper over fs
provided by nodejs.
Upvotes: 4
Reputation: 2943
Based on node.js documentation removeSync function not exist. For delete file use unlinkSync
function like this:
fs.unlinkSync(path)
But I don't think that work for multiple files, you can use glob package:
var glob = require("glob")
// options is optional
glob("/NodeWorkspace/uploads/output/*.csv", options, function (er, files) {
for (const file of files) {
fs.unlinkSync(file);
}
})
Note: Remember for delete directory use fs.rmdir();
Upvotes: 11