Permalink
Browse files

Fix problem with more files than 100 in a directory

  • Loading branch information...
1 parent cfd5134 commit a57046ada7cd28846f7c256ac29daabc98cd2212 @enyo enyo committed with Oct 13, 2015
Showing with 22 additions and 12 deletions.
  1. +22 −12 src/dropzone.coffee
View
@@ -890,18 +890,28 @@ class Dropzone extends Emitter
_addFilesFromDirectory: (directory, path) ->
dirReader = directory.createReader()
- entriesReader = (entries) =>
- for entry in entries
- if entry.isFile
- entry.file (file) =>
- return if @options.ignoreHiddenFiles and file.name.substring(0, 1) is '.'
- file.fullPath = "#{path}/#{file.name}"
- @addFile file
- else if entry.isDirectory
- @_addFilesFromDirectory entry, "#{path}/#{entry.name}"
- return
-
- dirReader.readEntries entriesReader, (error) -> console?.log? error
+ errorHandler = (error) -> console?.log? error
+
+ readEntries = () =>
+ dirReader.readEntries (entries) =>
+ if entries.length > 0
+ for entry in entries
+ if entry.isFile
+ entry.file (file) =>
+ return if @options.ignoreHiddenFiles and file.name.substring(0, 1) is '.'
+ file.fullPath = "#{path}/#{file.name}"
+ @addFile file
+ else if entry.isDirectory
+ @_addFilesFromDirectory entry, "#{path}/#{entry.name}"
+
+ # Recursively call readEntries() again, since browser only handle
+ # the first 100 entries.
+ # See: https://developer.mozilla.org/en-US/docs/Web/API/DirectoryReader#readEntries
+ readEntries()
+ return null
+ , errorHandler
+
+ readEntries()

0 comments on commit a57046a

Please sign in to comment.