Skip to content

Instantly share code, notes, and snippets.

@ValeriiVasin
Created June 3, 2013 22:05
Show Gist options
  • Select an option

  • Save ValeriiVasin/5701881 to your computer and use it in GitHub Desktop.

Select an option

Save ValeriiVasin/5701881 to your computer and use it in GitHub Desktop.
Remove folder with subfolders recursively.
// remove folder with all files and folders recursively
function removeFolderRecursive(path) {
if ( fs.existsSync(path) ) {
fs.readdirSync(path)
.forEach(function(file) {
var current = path + '/' + file;
if ( fs.statSync(current).isDirectory() ) {
removeFolderRecursive(current);
} else {
fs.unlinkSync(current);
}
});
fs.rmdirSync(path);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment