I want to traverse through a html5 file system and have some sort of notification once all files have been traversed.
Im using filer which is a wrapper for the html file system library
in order to start the recursive file system walker im using this:
filerService.ls(filerService.fs.root, function(entries){
for(var i = 0; i < entries.length; i ++) {
traverseFileTree(entries[i]);
}
});
the recursive function:
function traverseFileTree(item) {
if(item.isFile) {
console.log("item is file: " + item.name);
//do something with file here
} else if (item.isDirectory) {
console.log("item is directory: " + item.name);
filerService.ls(item, function(entries) {
for(var i = 0; i < entries.length; i ++) {
traverseFileTree(entries[i]);
}
});
}
};
Now I would like to do the following:
var promise = walkFileTree() //this method should start the recursive methods and return a promise
promise.then(function(){
//notify user that the filewalker has completed
})
anyone have some pointers on how this can be achieved?