Skip to content

Instantly share code, notes, and snippets.

@leotm
Last active August 29, 2015 14:25
Show Gist options
  • Save leotm/857e4cd0d1022a3004a5 to your computer and use it in GitHub Desktop.
Save leotm/857e4cd0d1022a3004a5 to your computer and use it in GitHub Desktop.
Node.js - Delete file(s)
var glob = require('glob');
var fs = require('fs');
// Find file(s)
glob('**/fileName.ext', function(err, files) {
if (err) { throw err; }
files.forEach(function(item, index, array) {
console.log(item + ' found');
// Delete file(s)
fs.unlink(item, function(err) {
if (err) { throw err; }
console.log(item + ' deleted');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment