Skip to content

Instantly share code, notes, and snippets.

@hengkiardo
Created November 14, 2013 11:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hengkiardo/7465436 to your computer and use it in GitHub Desktop.
Save hengkiardo/7465436 to your computer and use it in GitHub Desktop.
Remove a directory that is not empty in NodeJS
var deleteFolderRecursive = function(path) {
if( fs.existsSync(path) ) {
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.statSync(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