Need to allow users to select a custom folder to store data created by my app

Hello guys, does anyone know if it is possible to have a user select a custom location to store data generated by an application?

For example, the app can be installed in the usual in program files folder on a desktop/laptop machine as expected, that’s fine, but I need the user to be able to specify a separate location to store the actual data it generates on a separate drive. (ie. I don’t want it stored in the regular AppData folder on the C drive where Windows resides)

To elaborate, data is currently stored here:

C:\Documents and Settings\K\AppData\Local\ExeOutput\UserApplication{21FE3606-B80D-48F5-91C7-087755E2F39B}

I need users of my app to be able to specify a location like:


Is this currently possible?

No, because we must use a folder that is always accessible. You can customize the “ExeOutput\UserApplication{21FE3606-B80D-48F5-91C7-087755E2F39B}” part in ExeOutput, but you can’t specify absolute folders.

Hi Kim,

I was in a similar situation to you, I found a solution to this by using the shell_exec function to get the users local app data directory, however you could use the selectDirectory function in the HEScripts ( this should return the full path to your users folder of choice, saving this path in say an sqlite database or a json file in the data folder will allow your application when booting to check the files existence.

I also save files outside the recommended folders, this is so the user has access to all the generated pdfs (as an example) in a safe environment. the documents folder is where they’re comfortable accessing data so this is where I save and load pdfs so long as the folder is available.

However doing it this way could do harm so you’ll need checks in place to see if the folder and files still exist as a user could delete, move or rename these folders/files at any time.

The application I’ve build is installed to program files (x86) however all the data is stored in the users local appdata folder and any user accessible data is in the documents, these are all common places for applications and helps the user feel it’s more legitimate, however this could easily be argued.

Example script:

// Get the users local profile and then append any additional directories.
define('USERPROFILE', trim(shell_exec('echo %userprofile%')) . DIRECTORY_SEPARATOR . 'AppData' . DIRECTORY_SEPARATOR . 'Local' . DIRECTORY_SEPARATOR . 'Dearnex');

Then you can do something like this

if (file_exists(USERPROFILE) === false) {

// Finally you can begin saving files like this
file_put_contents(USERPROFILE . DIRECTORY_SEPARATOR . 'test-file.txt', 'This is a test file');

I hope this helps.


Thanks dearnex, that’s awesome - I’ll experiment with the code as soon as I get a chance.

In my case I just want to give the user the option to use a different drive due to the sheer amount of data my app generates over time, also would save on disk read/writes to the main OS drive which would be good too.

I’ll let you know how it goes!


1 Like