If I read a directory and then I wanted to cycle through those files and tell what is a directory with the path file name. How would you keep track of that file variable that? Or should I just be using the sync version?
Here's example code:
fs.readdir("../directory", function(err, files) {
if(err) throw err;
for(var i = 0; i < files.length; i++) {
fs.stat(files[i], function(err, stats) {
//files[i] will be files[ files.length - 1 ] when the callback is called
console.log("%s %s", files[i], stats.isDirectory())
});
}
});
It would be cool if you could pass in your own variables to fs.stat, like after the callback.