How do you get the selected directory path from file system access api window.showDirectoryPicker()
Asked Answered
P

1

7

When I choose a folder I do get a dirHandle but cannot figure out what property or method will give me the full path

const dirHandle = await window.showDirectoryPicker()

So something like let path = dirHandle.fullpath

Any ideas?

Pondicherry answered 18/9, 2021 at 16:28 Comment(0)
T
10

For security reasons the full path will not be revealed to web applications. You can only learn the relative paths by walking through a directory. In the example below, if the user opens shared/, you can learn about the existence of ./public and ./public/file.txt inside of it, but not that shared/ lies in secret/ and further up.

/root/secret/shared/public/file.txt
Therrien answered 9/11, 2021 at 12:31 Comment(2)
It makes sense. I've also found that with window.showSaveFilePicker() I can get the short name of the user-chosen file, but I won't know where it is.Mcallister
That's correct. showSaveFilePicker() lives up to the same security standards.Therrien

© 2022 - 2024 — McMap. All rights reserved.