Open folder in Windows Explorer using Native File System API

Viewed 1226
1 Answers

This is how I am opening a directory and store the handlers in an array

 try {
        const directoryHandle = await window.showDirectoryPicker()
        const files = []

        for await (let [name, handle] of directoryHandle) {
          const file = await handle.getFile()

         // if you want to access the content of the file 
         const content = await file.text()
         
         files.push({
            name,
            handle,
            file,
            content,
          })
        }
        console.log('', files)

More to read https://wicg.github.io/file-system-access/#filesystemdirectoryhandle

Related