3

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?

dan
  • 2,857
  • 6
  • 34
  • 60

1 Answers1

7

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
DenverCoder9
  • 2,024
  • 11
  • 32
  • 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. – Zhiyong Aug 11 '22 at 15:00
  • That's correct. `showSaveFilePicker()` lives up to the same security standards. – DenverCoder9 Aug 22 '22 at 08:22