Change option name to 'filters' and implimented filtering for synchronous walking

This commit is contained in:
ZECTBynmo 2013-04-20 16:29:37 -04:00
parent 6c4e267bd1
commit 85e84a0a3f
2 changed files with 25 additions and 10 deletions

View File

@ -33,8 +33,8 @@ The Synchronous version still uses callbacks, so it is safe to use with other As
options = {
followLinks: false,
// asyncFilters: ["Temp", "_Temp"] // directories with these
// keys will be skipped
// filters: ["Temp", "_Temp"] // directories with these
// keys will be skipped
};
walker = walk.walk("/tmp", options);

View File

@ -35,7 +35,7 @@
me._wq = [];
me._wqueue = [me._wq];
me._wcurpath = undefined;
me._wasyncFilters = options.asyncFilters;
me._wfilters = options.filters;
me._wfirstrun = true;
me._wcurpath = pathname;
@ -176,12 +176,27 @@
, me = this
;
try {
files = fs.readdirSync(me._wcurpath);
} catch(e) {
err = e;
// Stop directories that contain filter keywords
// from continuing through the walk process
if (me._wfilters != undefined) {
var shouldExclude = false;
for (var iFilter=0; iFilter<me._wfilters.length; ++iFilter) {
if (me._wcurpath.indexOf(me._wfilters[iFilter]) != -1 ) {
me._wNext();
}
}
}
if( !shouldExclude ) {
console.log(me._wcurpath);
try {
files = fs.readdirSync(me._wcurpath);
} catch(e) {
err = e;
}
} else console.log("excluding: " + me._wcurpath)
me._wReaddirHandler(err, files);
};
Walker.prototype._wWalkAsync = function () {
@ -190,10 +205,10 @@
// Stop directories that contain filter keywords
// from continuing through the walk process
if (me._wasyncFilters != undefined) {
if (me._wfilters != undefined) {
var shouldExclude = false;
for (var iFilter=0; iFilter<me._wasyncFilters.length; ++iFilter) {
if (me._wcurpath.indexOf(me._wasyncFilters[iFilter]) != -1 ) {
for (var iFilter=0; iFilter<me._wfilters.length; ++iFilter) {
if (me._wcurpath.indexOf(me._wfilters[iFilter]) != -1 ) {
me._wNext();
}
}