问题
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:
- Call
directoryEntry.createReader()
to create a newDirectoryReader
.- Call
readEntries()
.- 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