There are several possible ways of getting the path to the application data directory:
- using the
%APPDATA%environment variable - calling
SHGetFolderPathwithCSIDL_APPDATA
What is the best way to get the path from within an program? Are there any gotchas when I use the environment variable?
Which method is safest across XP, Vista and upcoming versions?
I would suggest that calling
SHGetFolderPath()is the most appropriate, and portable method; the alternatives, such as reading an environment variable, or (worse) trying to extract it from the registry are likely to trip you up in the future.Raymond Chen has an article explaining why pulling such paths from the registry is a bad idea.