File create()

Hello!

Another newbie question.

Windows 7 VS2010 and latest tip before the Quake.

I am working on making a serialfile that gets checked and changed by a plug-in. I can read files and can create files, but have some difficulties creating files in the right directories. When creating a file I want to use a path using the next code:

File myfile = File::getSpecialLocation(File::globalApplicationsDirectory).getChildFile("my company/keyfile.ersk"); myfile.create();

My problem is that the keyfile.ersk file does not get created. What mistake do I make?

Kind regards,

Harrie

I also tried:

File myfile = ("\\Program Files\Empty Room Systems\keyfile.ersk"); myfile.create();

but that does not create the file in any place. While

File myfile = ("keyfile.ersk"); myfile.create();

creates the file in the working directory. The working directory can be changed by the user, so is not the way to work for me I guess?

What am I missing?

i thing you need admin rights, or the windows UAC prevents you to write in these directories. Store your File into the user-controlled directories (Appdata etc.), have a look at the ApplicationProperties class…

That is a piece of the puzzle! Thanks you. I see that the next code works:

I am now testing with:

That does not seem to work. Do I need to set the ApplicationProperties to make File::commonApplicationDataDirectory part point to the right directory?

Thanks in advance!

Harrie

no!
I mean use the ApplicationProperties class, to save your data.

hmmm, that will need me to change from a series of strings to binary or xml format… I guess I have to rethink the entire structure I made. :?

I figured out that the userDocumentsDirectory does work on my W7 machine. I guess I need to test if this will on other (XP) machines as well.

Harrie

you can use File::userApplicationDataDirectory / YouAppName / yousettingsfile.settings
or just create a file along the normal settings file

const File keyfile (appProperties->getUserSettings() ->getFile().getSiblingFile ("keyFile"));

…and don’t write things like this!

getChildFile("my company/keyfile.ersk");

…instead, always use:

getChildFile("my company").getChildFile ("keyfile.ersk");

…so that you avoid platform-specific separator characters.

Thank you chkn and jules!

Harrie