Open Finder folder window from button

Yes, using shell.openPath actually opens a file Explorer window on Windows if you pass in the path to a folder. I use it so a user can see the folder containing the content generated by my plugin. doing this is of no use to my plugin, because I get no variable with which to manipulate the folder.

If you are interested in having programmatic control of any folder on the harddrive, such as being able to read and save files via javascript, you will need to use require('uxp').storage.localFileSystem .

  1. ask the user for the root drive (e.g. J:// ) by using localFileSystem.getFolder()
    Note: You will need to explicitly tell them to select the root drive using a pop up before calling getFolder()
  2. The folder they picked returns to you as a folderEntry object. Ensure its the root drive, and then use localFileSystem.createPersistentToken(folderEntry) to create a token, which allows you to get this file entry in the future without asking the user.
  3. Save the token to your plugin’s localStorage. In the future, when a user opens photoshop again, your code should check localStorage for the token, thus avoiding steps 1 and 2. Instead, you just call localFileSystem.getEntryForPersistentToken(token)

In order to access the subfolders, you need to write a function that calls getEntries() on your current folderEntry, find the right subfolder in that array, and then creates a new folderEntry or fileEntry from that, and then calls getEntries() again. You repeat this until you reach your desired folder or file. You could probably write a recursive function for this.

If someone knows a less convoluted way to access an entire drive, please share. This is the only method I found.

2 Likes