Skip to content

Instantly share code, notes, and snippets.

@ironboy
Created June 30, 2015 10:24
Show Gist options
  • Save ironboy/2b47933089dd093030b0 to your computer and use it in GitHub Desktop.
Save ironboy/2b47933089dd093030b0 to your computer and use it in GitHub Desktop.
function getFileNames(path,callback){
// Read a folder recursively looking for js files
var fs = require('fs'), base = {__count:0, arr: []};
recursiveReadDir(path);
// Recursor
function recursiveReadDir(path){
base.__count++;
fs.readdir(path,function(err,x){
base.__count--;
for(var j = 0; j < x.length; j++){
i = x[j];
if(i.indexOf(".") < 0 && !err){
recursiveReadDir(path + i + "/",callback);
}
else if (i.indexOf(".js") > 0){
base.arr.push(path + i);
}
}
if(base.__count === 0){callback(base.arr);}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment