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);
                    });
5
  • 1
    As a tip: make an event listener where you can check whether all the files was read and do your trick. Commented Sep 28, 2016 at 6:53
  • can you give me code to do this with using event listener and how to check all files was read Commented Sep 28, 2016 at 7:02
  • Possible duplicate of FileReader API: how to read files synchronously Commented Sep 28, 2016 at 7:09
  • @Frxstrem I don't thing that this is duplicate for this. This link only half of question Commented Sep 28, 2016 at 7:16
  • @murtazasanjeliwala provide more JS and HTML code if you need example. Commented Sep 28, 2016 at 7:18

1 Answer 1

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);
});
Sign up to request clarification or add additional context in comments.

2 Comments

files count is not fixed because in drag and drop folder there can be many files and folders inside parent folder, this is the problem. if it is fix than i dont require to ask you.
You can update this value on drop event. That's all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.