I am trying to determine if a directory tree has been fully traversed after is was dropped on a page. That is: I would like to know when the next process can start after the full folder and sub-directories has been process by the drop event code.
As an example, in the code below I want send the M.files via json to sever. To do this I need to know when the folder is processed. The Ajax call is not shown.
The recursive directory tree traversal function:
async function processEnt(ent,n,fls){
n = n==undefined? 0:n;
if( ent.isFile ){
fls.files.push(ent.name)
}
else if (ent.isDirectory){
fls.dirs[ent.name]={ "files":[], "dirs":{},"done":false }
var r = ent.createReader()
await r.readEntries(
async function f(ents){
if(ents.length >0){
for(var e of ents){
await processEnt(e,n+1,fls.dirs[ent.name])
}
await r.readEntries(f)
}
}
)
}
console.log(n +" level done")
}
The drop event function:
async function onDrop(evt){
evt.preventDefault()
evt.stopPropagation()
M.files = {
"files":[],
"dirs":{}
}
for(item of evt.dataTransfer.items){
await processEnt( item.webkitGetAsEntry(),0,M.files )
}
console.log("on drop done")
}