Change option name to 'filters' and implimented filtering for synchronous walking
This commit is contained in:
parent
6c4e267bd1
commit
85e84a0a3f
|
@ -33,7 +33,7 @@ The Synchronous version still uses callbacks, so it is safe to use with other As
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
followLinks: false,
|
followLinks: false,
|
||||||
// asyncFilters: ["Temp", "_Temp"] // directories with these
|
// filters: ["Temp", "_Temp"] // directories with these
|
||||||
// keys will be skipped
|
// keys will be skipped
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
23
lib/walk.js
23
lib/walk.js
|
@ -35,7 +35,7 @@
|
||||||
me._wq = [];
|
me._wq = [];
|
||||||
me._wqueue = [me._wq];
|
me._wqueue = [me._wq];
|
||||||
me._wcurpath = undefined;
|
me._wcurpath = undefined;
|
||||||
me._wasyncFilters = options.asyncFilters;
|
me._wfilters = options.filters;
|
||||||
me._wfirstrun = true;
|
me._wfirstrun = true;
|
||||||
me._wcurpath = pathname;
|
me._wcurpath = pathname;
|
||||||
|
|
||||||
|
@ -176,11 +176,26 @@
|
||||||
, me = this
|
, me = this
|
||||||
;
|
;
|
||||||
|
|
||||||
|
// 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 {
|
try {
|
||||||
files = fs.readdirSync(me._wcurpath);
|
files = fs.readdirSync(me._wcurpath);
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
err = e;
|
err = e;
|
||||||
}
|
}
|
||||||
|
} else console.log("excluding: " + me._wcurpath)
|
||||||
|
|
||||||
me._wReaddirHandler(err, files);
|
me._wReaddirHandler(err, files);
|
||||||
};
|
};
|
||||||
|
@ -190,10 +205,10 @@
|
||||||
|
|
||||||
// Stop directories that contain filter keywords
|
// Stop directories that contain filter keywords
|
||||||
// from continuing through the walk process
|
// from continuing through the walk process
|
||||||
if (me._wasyncFilters != undefined) {
|
if (me._wfilters != undefined) {
|
||||||
var shouldExclude = false;
|
var shouldExclude = false;
|
||||||
for (var iFilter=0; iFilter<me._wasyncFilters.length; ++iFilter) {
|
for (var iFilter=0; iFilter<me._wfilters.length; ++iFilter) {
|
||||||
if (me._wcurpath.indexOf(me._wasyncFilters[iFilter]) != -1 ) {
|
if (me._wcurpath.indexOf(me._wfilters[iFilter]) != -1 ) {
|
||||||
me._wNext();
|
me._wNext();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue