diff --git a/lib/wrench.js b/lib/wrench.js index 911c162..6e47f6a 100644 --- a/lib/wrench.js +++ b/lib/wrench.js @@ -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++) {