added failSilent option to wrench.rmdirSyncRecursive

for cases where you want to delete a directory that may or may not
exist:
wrench.rmdirSyncRecursive('dir', true);
This commit is contained in:
Dave Geddes 2012-01-10 12:38:39 -07:00
parent 45d751eeda
commit 7157760c12

View file

@ -13,15 +13,19 @@
var fs = require("fs");
/* wrench.rmdirSyncRecursive("directory_path");
/* wrench.rmdirSyncRecursive("directory_path", failSilent);
*
* Recursively dives through directories and obliterates everything about it. This is a
* Sync-function, which blocks things until it's done. No idea why anybody would want an
* Asynchronous version. :\
*/
exports.rmdirSyncRecursive = function(path) {
var files = fs.readdirSync(path),
currDir = path;
exports.rmdirSyncRecursive = function(path, failSilent) {
var files, currDir = path;
try { files = fs.readdirSync(path); }
catch (err) {
if (failSilent) return;
throw new Error(err.message);
}
/* Loop through and delete everything in the sub-tree after checking it */
for(var i = 0; i < files.length; i++) {