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:
parent
45d751eeda
commit
7157760c12
1 changed files with 8 additions and 4 deletions
|
|
@ -13,15 +13,19 @@
|
||||||
|
|
||||||
var fs = require("fs");
|
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
|
* 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
|
* Sync-function, which blocks things until it's done. No idea why anybody would want an
|
||||||
* Asynchronous version. :\
|
* Asynchronous version. :\
|
||||||
*/
|
*/
|
||||||
exports.rmdirSyncRecursive = function(path) {
|
exports.rmdirSyncRecursive = function(path, failSilent) {
|
||||||
var files = fs.readdirSync(path),
|
var files, currDir = path;
|
||||||
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 */
|
/* Loop through and delete everything in the sub-tree after checking it */
|
||||||
for(var i = 0; i < files.length; i++) {
|
for(var i = 0; i < files.length; i++) {
|
||||||
|
|
|
||||||
Reference in a new issue