Created
August 22, 2011 13:03
-
-
Save olostan/1162325 to your computer and use it in GitHub Desktop.
Recursive list of files
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 fs = require('fs'); | |
function dir(path, callback) { | |
var promises = 0; | |
var all = []; | |
function _dir(path) { | |
promises++; | |
fs.readdir(path, function(err,files) { | |
promises--; | |
if (err) throw err; | |
for(var f in files) { | |
var file = path+"/"+files[f]; | |
//console.log(file); | |
all.push(file); | |
function recurse(file) { | |
promises++; | |
this.callback = function(err, stats) { | |
promises--; | |
if (stats.isDirectory()) _dir(file); | |
if (promises==0) callback(all); | |
} | |
} | |
fs.stat(file,(new recurse(file)).callback); | |
} | |
}); | |
}; | |
_dir(path); | |
} | |
dir('.', function(list) { console.log(list.join("\n"));} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment