3

Note: There are already some questions on how to open Folder on User device using Javascript. however, these questions were asked, before the Native File System API.

  1. How to open Window File Explorer from web browser using javascript
  2. Open local folder from link
  3. Open a folder in finder/explorer from a webpage?

My question is very specific, is there a way to open a folder in default file explore (ie Windows Explorer in Windows and Finder in Mac) using the new "Native File System API".

Adarsh Madrecha
  • 6,364
  • 11
  • 69
  • 117

1 Answers1

1

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

ctwhome
  • 753
  • 1
  • 13
  • 24
  • How would I do them all at parralel? – Akxe Jun 04 '21 at 13:20
  • what do you mean? – ctwhome Jun 07 '21 at 07:16
  • I wanted to open and read all files in parallel, rather than wait to read the file close it and then read next. In my code, I only read the first 5000bits of the file so it is a reasonable thing to do :) I managed to do it with files being an array of promises of `handle.getFile().then(...)` – Akxe Jun 07 '21 at 09:07