Created
January 22, 2018 11:39
-
-
Save n1ru4l/51236d2038df71bfdb69ad9d1efbeb8b to your computer and use it in GitHub Desktop.
rm -rf
This file contains 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
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