Skip to content

Instantly share code, notes, and snippets.

@willbailey
Created March 2, 2011 19:20
Show Gist options
  • Save willbailey/851513 to your computer and use it in GitHub Desktop.
Save willbailey/851513 to your computer and use it in GitHub Desktop.
node list files matching a regex recursively
var fs = require('fs');
var listFiles = function(path, match) {
var files = [];
var paths = fs.readdirSync(path);
paths.forEach(function(file) {
var stats = fs.statSync(path + '/' + file);
if (stats.isDirectory()) {
files = files.concat(listFiles(path + '/' + file, match));
} else {
if (file.match(match)) {
files.push(file);
}
}
});
return files;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment