Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the %AppData% folder in C?

Tags:

c

windows

appdata

As above, how do I get the AppData folder in Windows using C?

I know that for C# you use Environment.SpecialFolder.ApplicationData

like image 795
Romulus Avatar asked Oct 18 '10 23:10

Romulus


People also ask

What is AppData in C drive?

What is the AppData folder? AppData is a hidden folder located in C:\Users\<username>\AppData. The AppData folder contains custom settings and other information needed by applications. For example, you might find the following in your AppData folder: Web browser bookmarks and cache.

Why is there no AppData folder?

Normally, you will not find the AppData folder in your User Profile page because it is hidden by default. We will change the hidden settings and then access the file location. Make sure that you are logged in as an administrator.

How do I access AppData from command prompt?

Search for "Run" in the windows search as shown below, or press the Windows + R button to open the Run App. In the run app text box, enter "%AppData%" and click OK. Windows will directly open up the Roaming folder which is inside the AppData folder.


2 Answers

Use SHGetSpecialFolderPath with a CSIDL set to the desired folder (probably CSIDL_APPDATA or CSIDL_LOCAL_APPDATA).

You can also use the newer SHGetFolderPath() and SHGetKnownFolderPath() functions. There's also SHGetKnownFolderIDList() and if you like COM there's IKnownFolder::GetPath().

like image 163
Ferruccio Avatar answered Sep 19 '22 00:09

Ferruccio


If I recall correctly it should just be

#include <stdlib.h>
getenv("APPDATA");

Edit: Just double-checked, works fine!

like image 37
Mr. Llama Avatar answered Sep 19 '22 00:09

Mr. Llama