Ullan
Ullan

Reputation: 1341

How to get the AppData path

SHGetSpecialFolderPathA(NULL,buffer, CSIDL_APPDATA,FALSE );

C:\Users\guest\AppData\Roaming

SHGetSpecialFolderPathA(NULL,buffer, CSIDL_LOCAL_APPDATA,FALSE );

C:\Users\guest\AppData\Local

Is there way to get the path C:\Users\guest\AppData using windows API's?

Upvotes: 1

Views: 7165

Answers (1)

Anders
Anders

Reputation: 101569

The roaming and local folders exist for a reason, sometimes you might need to put something in the root of the profile but you are not really supposed to do it. This is what MSDN says about CSIDL_PROFILE:

Applications should not create files or folders at this level; they should put their data under the locations referred to by CSIDL_APPDATA or CSIDL_LOCAL_APPDATA. However, if you are creating a new Known Folder the profile root referred to by CSIDL_PROFILE is appropriate.

On NT5 they don't even have the same parent folder and "Roaming" is in the root of the profile:

C:\Documents and Settings\username\Application Data
C:\Documents and Settings\username\Local Settings\Application Data

The user and/or domain admin can move and/or redirect those folders to anywhere, to the root of a different drive or a network share.

The only documented way I can think of to find the parent is to use IKnownFolderManager::GetFolder and then call IKnownFolder::GetFolderDefinition and look at KNOWNFOLDER_DEFINITION.fidParent (Keep in mind that there does not have to be a parent, IKnownFolderManager::Redirect takes a string as the target so a redirected folder can be anywhere)

If you want to exclude files under a special shell folder you should compare the path with something like PathCommonPrefix or IKnownFolderManager::FindFolderFromPath.

Upvotes: 3

Related Questions