Merge pull request #18 from ZECTBynmo/master

File path filters
Этот коммит содержится в:
AJ ONeal 2013-04-23 13:39:42 -07:00
родитель 42cdccff35 863a196262
Коммит 49e9260caa
2 изменённых файлов: 30 добавлений и 4 удалений

Просмотреть файл

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

Просмотреть файл

@ -35,6 +35,7 @@
me._wq = [];
me._wqueue = [me._wq];
me._wcurpath = undefined;
me._wfilters = options.filters;
me._wfirstrun = true;
me._wcurpath = pathname;
@ -175,10 +176,23 @@
, 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 ) {
try {
files = fs.readdirSync(me._wcurpath);
} catch(e) {
err = e;
}
}
me._wReaddirHandler(err, files);
@ -187,6 +201,16 @@
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?
fs.readdir(me._wcurpath, function (err, files) {
me._wReaddirHandler(err, files);