0

I am using FileReader for reading multiple files and folders through drag and drop in chrome using javascript. It is working properly, but problem is that i want to call function after all file and folder read completes. I can't because it is asyncronous operation and FileReaderSync is not supported in chrome. So is there any way to doing this?

this is my code,

entry.file(function (file) {

                        var reader = new FileReader();
                        reader.onloadend = function (e) {
                            data.push(this.result);

                        };

                        reader.readAsText(file);
                    });
murtaza sanjeliwala
  • 205
  • 1
  • 2
  • 12

1 Answers1

2

As an example of what can be used here. This is can't be used as "Copy&Paste" variant :

var filesCount = "give here number of files";

var callbackFunction = function(){
    if(data.length == filesCount ){
        Console.log( "Assume this as the end of all files reading" );
    }
}
entry.file(function (file) {

    var reader = new FileReader();
    reader.onloadend = function (e) {
        data.push(this.result);
        callbackFunction();
    };

    reader.readAsText(file);
});
xAqweRx
  • 1,236
  • 1
  • 10
  • 23