Created
September 29, 2010 20:18
-
-
Save c4milo/603459 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var files = []; | |
var wf_rlevel = 0; | |
util.walkfiles = function(_path, filter) { | |
if(fs.statSync(_path).isFile()) { | |
throw new Error(_path + ' is a file. You should provide a directory path'); | |
} | |
if(!filter) { | |
filter = '.*'; | |
} | |
var filenames = fs.readdirSync(_path); | |
var basedir = _path; | |
for(var name in filenames) { | |
var file = basedir + '/' + filenames[name]; | |
if(fs.statSync(file).isDirectory()) { | |
wf_rlevel++; | |
util.walkfiles(file, filter); | |
wf_rlevel--; | |
} | |
if(file.match(filter)) { | |
files.push(file); | |
} | |
} | |
if(wf_rlevel === 0) { | |
return files; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment