Skip to content

Instantly share code, notes, and snippets.

@elycruz
Last active August 29, 2015 14:15
Show Gist options
  • Save elycruz/51cb16baafcfca90cf72 to your computer and use it in GitHub Desktop.
Save elycruz/51cb16baafcfca90cf72 to your computer and use it in GitHub Desktop.
custom rmdirp for 'Windows.old' folder
/**
* 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