Skip to content

Instantly share code, notes, and snippets.

@n1ru4l
Created January 22, 2018 11:39
Show Gist options
  • Save n1ru4l/51236d2038df71bfdb69ad9d1efbeb8b to your computer and use it in GitHub Desktop.
Save n1ru4l/51236d2038df71bfdb69ad9d1efbeb8b to your computer and use it in GitHub Desktop.
rm -rf
function rmrf (fs, directory, callback) {
fs.readdir(directory, function (err, list) {
if (err) return callback(err);
async.everySeries(list, function (item, callback) {
var filename = path.join(directory, item);
var stats = fs.stat(filename, function (err, stat) {
if (err) return callback(err);
if (filename === '.' || filename === '..') return callback();
if (stat.isDirectory()) return rmrf(fs, filename, callback);
fs.unlink(filename, callback);
});
}, function () {
fs.rmdir(directory, callback);
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment