Skip to content

Instantly share code, notes, and snippets.

@jmoberly
Created March 3, 2014 22:17
Show Gist options
  • Save jmoberly/9335829 to your computer and use it in GitHub Desktop.
Save jmoberly/9335829 to your computer and use it in GitHub Desktop.
Recursively delete a folder in node.
var deleteFolderRecursive = function(path) {
if( fs.existsSync(path) ) {
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.lstatSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment