javascripthtmlwebfile-system-access-api

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


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?


Solution

  • 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