Merge pull request #18 from ZECTBynmo/master

File path filters
This commit is contained in:
AJ ONeal 2013-04-23 13:39:42 -07:00
commit 49e9260caa
2 changed files with 30 additions and 4 deletions

View File

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

View File

@ -35,6 +35,7 @@
me._wq = []; me._wq = [];
me._wqueue = [me._wq]; me._wqueue = [me._wq];
me._wcurpath = undefined; me._wcurpath = undefined;
me._wfilters = options.filters;
me._wfirstrun = true; me._wfirstrun = true;
me._wcurpath = pathname; me._wcurpath = pathname;
@ -175,11 +176,24 @@
, 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 ) {
try { try {
files = fs.readdirSync(me._wcurpath); files = fs.readdirSync(me._wcurpath);
} catch(e) { } catch(e) {
err = e; err = e;
} }
}
me._wReaddirHandler(err, files); me._wReaddirHandler(err, files);
}; };
@ -187,6 +201,16 @@
var me = this var me = this
; ;
// Stop directories that contain filter keywords
// from continuing through the walk process
if (me._wfilters != undefined) {
for (var iFilter=0; iFilter<me._wfilters.length; ++iFilter) {
if (me._wcurpath.indexOf(me._wfilters[iFilter]) != -1 ) {
me._wNext();
}
}
}
// TODO how to remove this anony? // TODO how to remove this anony?
fs.readdir(me._wcurpath, function (err, files) { fs.readdir(me._wcurpath, function (err, files) {
me._wReaddirHandler(err, files); me._wReaddirHandler(err, files);