File tree 1 file changed +22
-6
lines changed
1 file changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -19,12 +19,28 @@ export const traverseFileTree = async (entry: FileSystemEntry) => {
19
19
} , errorCallback )
20
20
} else if ( entry . isDirectory ) {
21
21
const dirReader = ( entry as FileSystemDirectoryEntry ) . createReader ( )
22
- dirReader . readEntries ( async ( entries ) => {
23
- for ( let i = 0 ; i < entries . length ; i ++ ) {
24
- await internalProcess ( entries [ i ] , path + entry . name + "/" )
25
- }
26
- resolve ( { } )
27
- } , errorCallback )
22
+ const readEntries = ( ) => {
23
+ dirReader . readEntries ( async ( entries ) => {
24
+ for ( let i = 0 ; i < entries . length ; i ++ ) {
25
+ await internalProcess ( entries [ i ] , path + entry . name + "/" )
26
+ }
27
+ resolve ( { } )
28
+ /**
29
+ why? https://stackoverflow.com/questions/3590058/does-html5-allow-drag-drop-upload-of-folders-or-a-folder-tree/53058574#53058574
30
+ Unfortunately none of the existing answers are completely correct because
31
+ readEntries will not necessarily return ALL the (file or directory) entries for a given directory.
32
+ This is part of the API specification (see Documentation section below).
33
+
34
+ To actually get all the files, we'll need to call readEntries repeatedly (for each directory we encounter)
35
+ until it returns an empty array. If we don't, we will miss some files/sub-directories in a directory
36
+ e.g. in Chrome, readEntries will only return at most 100 entries at a time.
37
+ */
38
+ if ( entries . length > 0 ) {
39
+ readEntries ( )
40
+ }
41
+ } , errorCallback )
42
+ }
43
+ readEntries ( )
28
44
}
29
45
} )
30
46
await promise
You can’t perform that action at this time.
0 commit comments