How can I get current user "Download" folder

Hi,

I would like to get the current user “Download” folder path?
The pure javascript does not support that.
How can I get it?

Thx
Karoly

1 Like

Hi @kaci65 ,

Unfortunately, UXP currently doesn’t allow you to “directly” access the downloads folder due to security concerns.

What you can do is to ask the user once to select their Downloads folder (or, if they prefer, they can select any other folder, as well). If it, for whatever use case you have, really has to be the Downloads folder, you could then also check if it is such a folder (I wouldn’t recommend that since system configuration can change this).

You can do this using const folder = await require('uxp').storage.localFileSystem.getFolder(). You could then, so that you don’t have to ask the user for the folder after every restart, create a persistent token from it (const token = await require('uxp').storage.localFileSystem.createPersistentToken(folder)) and store it (e.g., using local storage).

The example in https://www.adobe.io/photoshop/uxp/uxp/reference-js/Modules/uxp/Persistent%20File%20Storage/FileSystemProvider/#getentryforpersistenttokentoken, with a few slight modifications (e.g., getFolder instead of getFileForOpening) should probably get you pretty close to what you need.

You can also check out this sample which achieves something similar with the Plugins folder instead of the Downloads folder, but it essentially achieves the same (store a persistent token in local storage and if it isn’t there, i.e., on first usage, ask the user to select the folder manually).

I hope this helps,
Best,
Pablo

1 Like

Hi Pablo,

I will check it in my app.
Probably the manually folder selection is the key for solution.

Thank you!
Karoly

1 Like

I checked.
It works well.
Thank you again.

1 Like