|
-
Sep 3rd, 2017, 03:11 PM
#1
Thread Starter
Fanatic Member
[RESOLVED] Some questions about folder IDs
I have some questions about folder IDs
1. I know that Known Folders (aka "special folders") have IDs. They used to be CSIDL values but are now KnownFolderIDs.
2. Does every folder in a Windows file system have an ID? (Apparently the answer is YES, they have a PIDL)
3. How can I get the ID from a given folder path?
Most APIs seems to work in one direction - get the path for a known folder for a given ID. I want the reverse of that - given a folder path, what is the ID. What is the Shell function which does that? Some sample code would be most appreciated as well!
Last edited by AAraya; Sep 3rd, 2017 at 07:42 PM.
-
Sep 3rd, 2017, 06:11 PM
#2
Re: Some questions about folder IDs
The API you are looking for is ILCreateFromPath.
You need to use CoTaskMemFree when you are done (or ILFree).
Declarations:
Code:
Private Declare Function ILCreateFromPath Lib "shell32.dll" Alias "ILCreateFromPathW" (ByVal szPath As String) As Long
Private Declare Sub CoTaskMemFree Lib "ole32.dll" (ByVal pv As Long)
Here you can see code using it.
-
Sep 3rd, 2017, 07:27 PM
#3
Thread Starter
Fanatic Member
Re: Some questions about folder IDs
Thanks Eduardo!
I'm confused however and maybe you can help me. There are two different ways for me to get the PIDL for the Recycle Bin:
1. Use ILCreateFromPath passing it the path to the Recycle Bin (on my computer C:\$Recycle.Bin)
2. Use SHGetFolderLocation passing it the CSIDL of the Recycle Bin (CSIDL_BITBUCKET)
I would expect both methods to return the same PIDL for the Recycle Bin yet that is not the case. Any idea why?
-
Sep 3rd, 2017, 10:06 PM
#4
Re: Some questions about folder IDs
When I was writing the my previous post I was wondering that: if the path send to ILCreateFromPath is one of a known special folder, if the function would return the same ID as do SHGetKnownFolderIDList or SHGetSpecialFolderLocation for a know folder like Program files or the Windows directory.
Your experience seems to show that it's not the case.
I really don't know why and how all that work.
I hope someone else knows more about folders IDs and can clarify that.
-
Sep 4th, 2017, 03:14 AM
#5
Re: Some questions about folder IDs
Sorry I wasn't around sooner but I've answered you about this in the KnownFolders thread (and for anyone else interested):
[VB6, Vista+] Code snippet: KnownFolders made easy with IKnownFolderManager
It's an oleexp project; and the mIID.bas addon that comes with it has all the FOLDERID_ GUIDs.
Or if you prefer, there's APIs, including SHGetKnownFolderPath (SHGetFolderPath now just wraps this function), to get the path of a KnownFolder from its GUID, but if you want to go path->GUID/object, you'll need the IKnownFolderManager.
The recycle bin is an odd item. It seems to have both a virtual representation and a hard path. So pidls can point to one or the other depending on the function.
The pidl structure is more complex than you'd think too; even with non-special folders, different methods of getting a pidl (ILCreateFromPath, IShellFolder for example) will return different values, but point to the same location.
-
Sep 4th, 2017, 10:47 AM
#6
Thread Starter
Fanatic Member
Re: Some questions about folder IDs
Thanks for the information guys. I'm going to close this as resolved.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|