Searching for images in the filesystem using a recursive deferred approach

I've been attempting to iterate through the Android file system in search of any images. I created the following recursive method, but it's not functioning as expected. I've been struggling to determine a condition that can identify the end of the recursion and return the results.

 getEntries: function(path, def, deepCount, results) {
        var self = this;
        var deferred = def || $q.defer();
        var deepCount = deepCount || 0;
        var results = results || [];
        
        window.resolveLocalFileSystemURL(path, function(fileSystem) {
            var directoryReader = fileSystem.createReader();
            directoryReader.readEntries(function(entries) {
                var arrayLength = entries.length;

                for (var i = 0; i < arrayLength; i++) {
                    var file = entries[i];
                   
                    if(file.isDirectory){
                        deepCount += 1;
                        self.getEntries(file.nativeURL, deferred, deepCount, results);                            
                    }
                    else if (file.isFile){
                        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 deferred.promise;
    },

Answer №1

After encountering a challenge, I decided to refer to the suggested solution in the query - How can I iterate through file system directories and files using javascript?

Upon further investigation, I realized that the issue with my method was the recursive invocation of window.resolveLocalFileSystemURL, which was causing the complication. Instead, I should be iterating through the directories directly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can we use jQuery to compare two blocks and set them to have the same height value?

Is there a way to compare and set equal height for two blocks within the main div? <div class="main-content"> <div class="content-1"></div> <div class="content-2"></div> </div> Javascript Code: var $content1 = $(&ap ...

Utilizing Jquery to enhance slide image transitions with navigational links

As a newcomer to jQuery, I am attempting to create a slider using jQuery. Here is the script I have so far: $(function() { var bgCounter = 0, text = [ 'some html code here', 'some html code here', 'some ...

How can I use Node.js Express to send a response in a file format like JavaScript or another type?

Currently, I have a piece of code that successfully reads the 'example.js' file and sends it to the client as requested. app.get('/mods/example.js', function(req, res) { fs.readFile('./mods/example.js', {encod ...

Combining the powers of Nextjs and Vue

Currently utilizing Vue.js, I am now looking to leverage the Next.js framework for its SEO capabilities, server-side rendering features, and other advantages. While I do have some experience with React, my primary focus is on mastering Vue.js. Is it poss ...

If the FedEx function does not receive a payment, it will need to return a value of Payment Required

I am struggling with understanding functions, parameters, and arguments in JavaScript as I am new to it. My goal is to have a function that returns different values based on the payment amount. If no payment is passed, it should return "Payment Required", ...

Serve the JS files in Express separately

I am facing issues with my webapp loading too slowly when using the express.static middleware to serve all my js files. I am considering serving each js file only when needed, such as when serving the html from jade that uses the js file. I have attempted ...

Having trouble executing multiple file uploads with node.js resulting in an ERR_EMPTY_RESPONSE?

Currently, I am attempting to upload multiple files on FTP using node.js. Everything seems to be going smoothly as the files are successfully uploaded to the server location. However, after some time passes, I do not receive a success message. Instead, I e ...

When configuring an app with UI Router, utilize the $http service

I am working on a project using Angular UI Router and Coach Potato. I want the UI Router states to load from the server side and then be added to the state provider in the Angular app.config. However, I am encountering an issue where I cannot inject the $h ...

Similar to AngularJS, jQuery also provides a powerful tool for submitting forms

Recently, I've delved into the world of angularjs and have been truly amazed by its capabilities so far. One thing that took me by surprise was the lack of a simple solution for sending AJAX requests using the $http service. After hours of searching G ...

Could you identify any issues with the main.xml file?

I have encountered an issue with my main.xml file as I switch to the graphical layout view. Instead of seeing the expected layout, all I see is a grey screen with an error message. The error message states: "Exception raised during rendering: com.android. ...

Having trouble figuring out how to load images into a div based on the current page location?

Looking for a solution to my problem - I have a navigation bar with a fixed div (A) on the far right side. The nav bar remains at the top of the page. There are 6 sections in the body of the page, each being 1200px tall divs. What I want is for a different ...

Is it possible to implement pagination for loading JSON data in chunks in jsGrid?

Currently, I am utilizing jsgrid and facing an issue with loading a JSON file containing 5000 registries into a grid page by page. My goal is to display only 50 registries per page without loading all 5000 at once. Even though I have implemented paging in ...

Is there a way retrieve all named HTML tags and store them in an array?

In need of assistance with parsing data from a page that is formatted as follows: <tag>dataIwant</tag> <tag>dataIwant</tag> <tag>dataIwant</tag> <othertag>moarData</othertag> <othertag>moarData</oth ...

A guide to sorting an array based on user input using Javascript

I have developed an app that utilizes JavaScript and the VueJS framework. I am currently working on implementing a 'dropdown' feature for items that are dynamically filtered based on user input. Below is the code snippet responsible for renderin ...

Why do I receive the error message "Error: Objects are not valid as a React child (found: [object Promise])" in NextJS13?

I'm feeling overwhelmed by this issue and unsure of how to resolve it. Here is the code that is causing trouble: 'use client' import React, { useState } from 'react' import AnimatedDiv from '../../../(shop)/(components)/animat ...

Encountering an issue with the date pipe in Angular that prevents

I'm trying to incorporate a date pipe in my AngularJS and Firebase project to display the creation date of a post. However, I am facing an issue where the date does not appear when testing it. Below is my create Post function: createPost() { con ...

Using AngularJS $resource to implement complex service calls

Yesterday, I began my journey with angularjs and found myself at this particular section of the tutorial that demonstrates the usage of $resource to access data from services. In my ASP.Net MVC setup, I encountered a slight hiccup due to the difference in ...

An issue arises when attempting to utilize URL parameters within a loader

In my React project, I am utilizing React-Router. The code for my movie page is as follows: import React from "react"; import axios from 'axios' export async function loader({ params }) { const movieId = params.movieId; const mov ...

What is causing this error/bug to show up in Angular?

I encountered an error while working on my Angular project that incorporates both front-end and back-end development with Python Flask. Even though the page updates correctly, a database-related error is being displayed in the console. Below are the snippe ...

The variable "Window" is not defined

How come I am unable to use Window.FEATURE_NO_TITLE? When I try to implement it, I receive an error saying Window is not recognized as a variable and the import option does not appear in the dialog box. dialog_shownote = new Dialog(WrittenTest.this, R.s ...