Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #18 from ZECTBynmo/master

File path filters
  • Loading branch information...
commit 49e9260caa2104bbffaf8185f84c7cd2aa9b20a7 2 parents 42cdccf + 863a196
@coolaj86 authored
Showing with 30 additions and 4 deletions.
  1. +2 −0  README.md
  2. +28 −4 lib/walk.js
View
2  README.md
@@ -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);
View
32 lib/walk.js
@@ -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);
Please sign in to comment.
Something went wrong with that request. Please try again.