javascript - Recursive deferred Filesystem search for images -


i'm trying loop through android file system images. wrote below recursive method, not working. tried use same defer through out recursion i'm unable find condition can recognize end of recursion , return results.

 getentries: function(path, def, deepcount, results) {         var self = this;         var deferred = def || $q.defer();         var deepcount = deepcount || 0;         var results = results || [];         // $cordovadialogs.alert("inside entries");         window.resolvelocalfilesystemurl(path, function(filesystem) {             var directoryreader = filesystem.createreader();             directoryreader.readentries(function(entries) {                 var arraylength = entries.length;                  // var log = [];                 // angular.foreach(entries, function(value, key) {                 //   if(key.isdirectory )                 // });               //  $cordovadialogs.alert("got entries");                 (var = 0; < arraylength; i++) {                     var file = entries[i];                    // $cordovadialogs.alert(file);                                        if(file.isdirectory){                         deepcount += 1;                         self.getentries(file.nativeurl, deferred, deepcount, results);                                                 }                     else if (file.isfile){                         //check if file extension of type image                         if(file.name.match(/\.(jpg|jpeg|png|gif)$/)){                             results.push(file.nativeurl);                         }                     }                 }                 if (!def && deepcount == 1 ) {                      deferred.resolve(results);                 }                 else {                     deepcount -= 1;                 }             }, function(error) {                 deferred.reject(error);                console.log(error);             });         }, function(error) {             deferred.reject(error);             console.log(error);          });         //return results;         return deferred.promise;     }, 

i ended following solution given in question- how iterate through file system directories , files using javascript?

however, noticed problem approach was, calling window.resolvelocalfilesystemurl in recursive call, causing problem. should looping through directories.


Comments

Popular posts from this blog

yii2 - Yii 2 Running a Cron in the basic template -

asp.net - 'System.Web.HttpContext' does not contain a definition for 'GetOwinContext' Mystery -

mercurial graft feature, can it copy? -