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

左心房为你撑大大i 提交于 2019-12-22 06:27:06

问题


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();

回答1:


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.


来源:https://stackoverflow.com/questions/23823548/maximum-files-of-a-directory-that-can-be-read-by-filereaderreadentries-in-javas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!