Created
February 1, 2012 07:47
-
-
Save hughsk/1715822 to your computer and use it in GitHub Desktop.
Synchronous `rmdir --recursive` for NodeJS.
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
// Thanks to [liangzan's gist](https://gist.github.com/807712) | |
rmdirSyncForce = function(path) { | |
var files, file, fileStats, i, filesLength; | |
if (path[path.length - 1] !== '/') { | |
path = path + '/'; | |
} | |
files = fs.readdirSync(path); | |
filesLength = files.length; | |
if (filesLength) { | |
for (i = 0; i < filesLength; i += 1) { | |
file = files[i]; | |
fileStats = fs.statSync(path + file); | |
if (fileStats.isFile()) { | |
fs.unlinkSync(path + file); | |
} | |
if (fileStats.isDirectory()) { | |
rmdirSyncForce(path + file); | |
} | |
} | |
} | |
fs.rmdirSync(path); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment