Last active
August 29, 2015 14:15
-
-
Save elycruz/51cb16baafcfca90cf72 to your computer and use it in GitHub Desktop.
custom rmdirp for 'Windows.old' folder
This file contains hidden or 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
/** | |
* Short script (**Note** needs to run with `--harmony` flag (testing on node 0.12.0)) | |
* for getting rid of the 'Windows.old' folder and also is a custom rmdirp of sorts: overcomes the memory limitations of the rmdirp module when running on windows (and maybe linux?). | |
* Just replace `pathToOperateOn` with the location of your 'Windows.old' folder. | |
* Run it and celebrate! :-D (thumbsup)! | |
* (Also excuse the big tabs/spaces. Had some issues with my pc, had no software installed and use notepad to write it lol!) | |
*/ | |
var fs = require('fs'), | |
path = require('path'), | |
pathToOperateOn = 'C:\Windows.old', | |
fileListToDelete = [], | |
log = console.log, | |
buildFileListToDelete = (dir) => { | |
var files = fs.readdirSync(dir); | |
files.forEach((file) => { | |
var retVal = path.join(dir, file), | |
stat = fs.statSync(retVal); | |
if (stat.isDirectory()) { | |
buildFileListToDelete(retVal); | |
} | |
fileListToDelete.push(retVal); | |
}); | |
}, | |
processFileListToDelete = () => { | |
for (var i = 0; i < fileListToDelete.length - 1; i += 1) { | |
var file = fileListToDelete[i], | |
stat = fs.statSync(file); | |
if (stat.isDirectory()) { | |
log(file, 'is a directory.'); | |
fs.rmdirSync(file); | |
} | |
else if (stat.isFile()) { | |
log(file, ' is a file.'); | |
fs.unlinkSync(file); | |
} | |
} | |
}; | |
buildFileListToDelete(pathToOperateOn); | |
processFileListToDelete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment