Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maximum files of a directory that can be read by FileReader#readEntries in JavaScript

I'm creating a Chrome application. I must read the files of a directory and I am using the DirectoryEntry API and DirectoryReader API.

My problem is that the maximum files read using DirectoryReader#readEntries is 100, the first 100 (alphabetical order)

var reader = currentDir.createReader();
var read = reader.readEntries.bind(reader, function(files) {
    for ( var i = 0; i < files.length; i++){
         if (files[i].name == nameSearches){
                callback(files[i]);
            }

        }
    })
    callback(undefined)
}
read();

The value of files.length is 100 and there are more files in the directory

I'm not sure if this limitation is about Google Chrome, Google Chrome Applications, Javascript... and if this limitation can be overcomed

With the solution marked the result code is this:

var reader = currentDir.createReader();
var read = reader.readEntries.bind(reader, function(files) {
    if (files.lenght == 0) {
        callback(undefined);
    }
    for ( var i = 0; i < files.length; i++){
        if (files[i].name == nameSearches){
                callback(files[i]);
            }

        }
    })
    read();

}
read();
like image 385
fhuertas Avatar asked May 23 '14 07:05

fhuertas


1 Answers

Read the docs you linked!

The only method for this interface, readEntries() is for listing all the files and folders in a directory. To list all the entries, you need to do the following:

  1. Call directoryEntry.createReader() to create a new DirectoryReader.
  2. Call readEntries().
  3. Continue calling readEntries() until an empty array is returned. You have to do this because the API might not return all entries in a single call.
like image 99
Xan Avatar answered Sep 24 '22 00:09

Xan