Move File Into Application Support

Hi everyone.

I'm struggling right now with figuring out a way to move a juce::File (which is a vital file for the operation of my app) into an Application Support folder on the hard drive.


It's a simple text file called 'user.reg'. It needs to be located at:

    /Library/Application Support/MY COMPANY/MY PRODUCT/user.reg

... but moving the file there is not working for me. I'm having 'permission denied' problems. Solutions I've thought of and tried:

 - Making my app require a password / run as administrator. I could not for the life of me figure out how to make this happen.

  - Using std::system to run a sudo mv command. Not working either.


The only other solution I've got is to create a temporary folder somewhere it will be erased eventually, put the file and an alias to the folder it's going to go in, and make the user manually 'drag the file' onto the alias to manually place it properly.

I mean, I'm totally sure that I'm missing something very convenient/obvious JUCE has built in that will help with these types of scenarios! It can't possibly be this complicated to move a file into Application Support! .... right?

Sorry to bump but I need an answer!


If it's not possible, then I just need to know! Then I can move forward with alternatives.

I think you will need to get admin privilages to achieve this which is a bit of a ball ache. However the simple solution is to have a pkg installer do the work for you, would this be possible for you?

If so check out it will make your life so much easier!

The other option come to think of it is to use ~/Library/Application Support I suspect you will be fine adding files in there.

If you want to add Authorization to your application (which should allow you access to these rescrited directories) I think this document will help...

You could also have a look at File::getSpecialLocation (File::commonDocumentsDirectory).

That's a place where you can read and write, and it's shared among all users on the system.

It really depends on what you need to do with the file. 

Just guessing, based on the fact that you have mentioned the file being named "user.reg", my strong advice if it is something user-related, is to store it in the user domain, thus starting from its home directory. In this case, File::getSpecialLocation (File::userApplicationDataDirectory) is your friend (and all the other File::userSomething entries of that enum).