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?
Asked
Active
Viewed 937 times
3
-
Like this? https://web.dev/file-system-access/#specifying-a-suggested-file-name-and-start-directory – Robert Harvey Nov 08 '21 at 22:40
-
Not really, what i'm trying to achieve is to basically set the FileSystemDirectoryHandle programmatically so not showing the file explorer at all but would still be asking permission... – gby Nov 08 '21 at 22:53
-
Like this? https://developer.mozilla.org/en-US/docs/Web/API/FileSystemDirectoryHandle/getDirectoryHandle – Robert Harvey Nov 08 '21 at 22:55
-
Nope, that would be just for getting the subdirectories. I would still need the 'root' directory which is what I want to set programmatically. – gby Nov 08 '21 at 23:00
1 Answers
1
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.

DenverCoder9
- 2,024
- 11
- 32
-
This unfortunately isn't possible in an extension (bugs [#1368818](https://bugs.chromium.org/p/chromium/issues/detail?id=1368818)/etc). I don't suppose you know of any other options? – EML Aug 19 '23 at 17:45
-
The main bug to track is [crbug/1359786](https://crbug.com/1359786) (your linked one was merged into that one). Until this is resolved, unfortunately there's no other way around it. – DenverCoder9 Aug 25 '23 at 10:37