Created
July 20, 2019 11:59
-
-
Save adrianjost/1bca0be7af6b71078d62cb2da1f1f941 to your computer and use it in GitHub Desktop.
How to create a filetree from the webbrowser drop event.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const traverseFiles = async (item) => { | |
if(item.isFile){ | |
return { file: item.file(), path: item.fullPath }; | |
}else if(item.isDirectory){ | |
const entries = await new Promise(resolve => item.createReader().readEntries(resolve)); | |
const files = await Promise.all(entries.map(traverseFiles)); | |
return { path: item.fullPath, files }; | |
} | |
} | |
document.getElementById("#drop").addEventListener("drop", (event) => { | |
const filetree = Promise.all( | |
Array.from(event.dataTransfer.items).map(item => | |
traverseFiles(item.webkitGetAsEntry()) | |
)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment