Board index » cppbuilder » FindFirst vs. PIDL
=?utf-8?Q?Asger_J=C3=B8rgensen?=
![]() CBuilder Developer |
=?utf-8?Q?Asger_J=C3=B8rgensen?=
![]() CBuilder Developer |
FindFirst vs. PIDL2007-10-17 07:28:53 PM cppbuilder82 Hi there I am trying to learn here. I have a program that search the disk for all folders and files using FindFirstFile, FindNextFile. If it is possible I would like to try and use PIDL's instead, but I have newer worked with PIDL's. If someone could give me some pointer on how to go about this, I will apriciate it very much. Thanks in advance Asger |
Mehmet Caner
![]() CBuilder Developer |
2007-10-17 10:37:41 PM
Re:FindFirst vs. PIDL |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2007-10-18 01:03:15 AM
Re:FindFirst vs. PIDL
"Asger Jørgensen" < XXXX@XXXXX.COM >wrote in message
QuoteIf it is possible I would like to try and use PIDL's namespace, then use its ParseDisplayName() and BindToObject() methods to get the IShellFolder for the specific folder that you want to begin searching from, then use that IShellFolder's EnumObjects() method to enumerate its subfolders and files. For each subfolder, call the parent IShellFolder's BindToObject() to get the IShellFolder for the subfolder, then call its EnumObjects() method, repeating recursively as needed. For example: void SearchFolder(IShellFolder *ParentFolder, LPITEMIDLIST pidlSubFolder) { IShellFolder *SubFolder = NULL; if( SUCCEEDED(ParentFolder->BindToObject(pidlSubFolder, NULL, IID_IShellFolder, (LPVOID*)&SubFolder)) ) { IEnumIDList *Enum = NULL; if( SUCCEEDED(SubFolder->EnumObjects(NULL, SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &Enum)) ) { LPITEMIDLIST pidlItem; while( Enum->Next(1, &pidlItem, NULL) == S_OK ) { // compare pidlItem to your search criteria as needed, // such as by calling SubFolder->GetDisplayNameOf(pidlItem, ...) // and other IShellFolder methods to get information // about the current item... ULONG ulAttr = 0; if( SUCCEEDED(SubFolder->GetAttributesOf(1, &pidlItem, &ulAttr)) ) { if( ulAttr & SFGAO_FOLDER ) SearchFolder(SubFolder, pidlItem); } CoTaskMemFree(pidlItem); } Enum->Release(); } SubFolder->Release(); } } { IShellFolder *Desktop = NULL; if( SUCCEEDED(SHGetDesktopFolder(&Desktop)) ) { ULONG eaten = 0; LPITEMIDLIST pidlFolder = NULL; if( SUCCEEDED(Desktop->ParseDisplayName(NULL, NULL, WideString("The starting path here"), &eaten, &pidlFolder, NULL)) ) { SearchFolder(Desktop, pidlFolder); CoTaskMemFree(pidlFolder); } Desktop->Release(); } } Gambit {smallsort} |
Ed Mulroy [TeamB]
![]() CBuilder Developer |
2007-10-18 01:44:16 AM
Re:FindFirst vs. PIDL
Now there is an {*word*118} problem with a non-obvious solution. I'm keeping a
copy of that one! . Ed QuoteRemy Lebeau wrote in message |
Remy Lebeau (TeamB)
![]() CBuilder Developer |
2007-10-18 03:48:20 AM
Re:FindFirst vs. PIDL
"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
QuoteNow there is an {*word*118} problem with a non-obvious solution. filenames/paths, but also physical filenames/path are represented as well. So it is good to know what Windows is doing internally to access those kinds of things generically. Gambit |
=?utf-8?Q?Asger_J=C3=B8rgensen?=
![]() CBuilder Developer |
2007-10-18 07:18:11 AM
Re:FindFirst vs. PIDL
Thanks Remy
This looks just like, what I need. One little error though. This line: if( SUCCEEDED(SubFolder->GetAttributesOf(1, &pidlItem, &ulAttr)) ) Should be: if( SUCCEEDED(SubFolder->GetAttributesOf(1, (LPCITEMIDLIST*)&pidlItem, &ulAttr)) ) But of cource You know that..;-) Thanks again Kind regards Asger |
=?utf-8?Q?Asger_J=C3=B8rgensen?=
![]() CBuilder Developer |
2007-10-18 07:19:42 AM
Re:FindFirst vs. PIDL
Thanks for the link Mehmet
Combined with what Remy provided I think I got it now. Kind regards Asger |