Last active
August 29, 2015 14:25
-
-
Save leotm/857e4cd0d1022a3004a5 to your computer and use it in GitHub Desktop.
Node.js - Delete file(s)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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