Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best way of getting path to "Application Data" directory?

Tags:

path

winapi

There are several possible ways of getting the path to the application data directory:

  • using the %APPDATA% environment variable
  • calling SHGetFolderPath with CSIDL_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?

like image 509
Torsten Marek Avatar asked Jan 31 '09 16:01

Torsten Marek


People also ask

What is the file path to AppData?

AppData is a hidden folder located in C:\Users\<username>\AppData.

What is the shortcut for AppData?

Direct access Tap the Win+R keyboard shortcut to open the run box. In the run box, enter %AppData% , and tap the Enter key. A new File Explorer window will open to the AppData's Roaming folder. Click the 'AppData' folder in the location bar to go to the main AppData folder.

Can you move AppData to another drive?

Unfortunately you cannot move AppData folder to another drive. Moving AppData folder to another drive might cause system stability. AppData or Application data is a hidden folder in Windows 8/8.1. It is to protect user data and settings from any unwanted change or deletion.


1 Answers

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.

like image 76
Rob Avatar answered Sep 28 '22 00:09

Rob