javascripthtml5-filesystemnative-file-system-api-jsfile-system-access-api

Is there a way to programmatically set the default directory with File System Access API


Is there a way to set a defined directory path programmatically instead of showing the file explorer with .showDirectoryPicker() for the user to select the actual path?


Solution

  • You need to obtain a handle to your desired root directory once via showDirectoryPicker(). You can from thereon store the handle to the directory in IndexedDB and continue from there, even after a reload. Note, though, that you need to check permissions each time, since once granted permissions are not restored, but must be re-obtained each time, at least for the moment.