this question is just for curiosity. I know there are other approaches to do the actual thing. I just want to learn some async patterns.
I wanted to search for specific files beginning from a root directory. So I discovered the file module:
https://github.com/mikeal/node-utils/tree/master/file
This module offers a async file.walk(start, callback) function. Where the callback is called for each found directory.
Imagine the case I would like to find all files with a specific name, save the path in an array and do something collaborative processing on them later.
import file = require("file");
var folderArray= [];
file.walk(path,function(err,file){
if(doesExist(file+"/mySpecialFileName")){
folderArray.push(file);
}
})
//when all sub directories are searched do something
process(folderArray)
How can I be sure that all directories are searched and I can progress with processing. For example in the dive module: https://github.com/pvorb/node-dive I would just put my process(folderArray) in the third callback which is called when the search is finished.
Thanks a lot. Best P