Detecting Application Data Directory

Started by
4 comments, last by Tolito 11 years, 9 months ago
Is there a program in Windows in the System32 folder that I can call that returns the Application Data directory, or how should I go about making the program determine where to store Application Data? It is different for many versions of Windows, and with there being more versions of Windows coming up in the future, I cannot just make an array with possible directories because I would need to update that with each Windows release. Please give an informative example of how to detect exactly there the Application Data is to be stored. Thank you. :)
Advertisement
I believe the environment variable [font=courier new,courier,monospace]%APPDATA%[/font] is set for all reasonable versions of Windows you may be targeting (from Windows 2K and up, I believe). So something like [font=courier new,courier,monospace]filepath = "%APPDATA%\\folder\\file.txt";[/font]

You shouldn't need to call a program. But if you do [font=courier new,courier,monospace]Start -> Run... -> %APPDATA%[/font] it should pop up an Explorer window with the appropriate folder open, if you're curious.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
Thank you for this tip. I tried this and it printed %APPDATA% just the same, however, so there must be more to it than this. Also, creating the directory will need to be done by the installer I create, correct?
Although it's C++, perhaps it will be of some use: http://stackoverflow...windows-using-c

If you have access to the registry, you can read HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\User Shell Folders\AppData, as documented here: http://technet.micro...y/cc962614.aspx
SHGetKnownFolderPath appears to be the current official way of doing this: http://msdn.microsof...8(v=vs.85).aspx

If you're creating an installer I'd highly recommend that you use a well-known installer technology rather than trying to roll your own. Visual Studio, for example, can be used to create an MSI file, and it will resolve all of this for you, as well as provide for uninstallation (and also be compatible with remote deployment via e.g. Group Policy).

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

This is exactly what I needed. Thank you all! :D

This topic is closed to new replies.

Advertisement