I have the following javascript code

    processEntry = function(entry){
        var dirReader =  entry.createReader();

        var hasFolders = false;
        var hasFiles = false;

        dirReader.readEntries(function(entries) {

            for (var i=0; i < entries.length; i++) {

                var currentEntry = entries[i]
                if (currentEntry.isFile){
                    if(currentEntry.name != 'DS_Store'){
                        hasFiles = true;
                        console.log(entry.name,'has files value is',hasFiles);
                    }
                } else if (currentEntry.isDirectory){
                    hasFolders = true;
                    console.log(entry.name,'has folders value is',hasFolders);
                }

            }
        });
        console.log(entry.name,'has files value is',hasFiles);
        console.log(entry.name,'has folders value is',hasFolders);

        //other code that depends on those values
}

The problem is, the first console log statements print correctly but for the second ones, they are always false. This means that the other code is never executed since the booleans say that all entries have no folders and no files. The entries are printing to the console correctly.

The entry is obtained by this line of code :

var entry = e.dataTransfer.items[i].webkitGetAsEntry();

I don't have much experience with Javascript.

0

There are 0 answers