Board index » cppbuilder » FindFirst vs. PIDL

FindFirst vs. PIDL


2007-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
 
 

Re:FindFirst vs. PIDL

"Asger Jørgensen" < XXXX@XXXXX.COM >wrote in message
Quote
If it is possible I would like to try and use PIDL's
instead
You will have to use the IShellFolder interface for that. Use
SHGetDesktopFolder() to get the IShellFolder for the top-level Desktop
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}

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
Quote
Remy Lebeau wrote in message
news:4716407d$ XXXX@XXXXX.COM ...
 

Re:FindFirst vs. PIDL

"Ed Mulroy [TeamB]" < XXXX@XXXXX.COM >wrote in message
Quote
Now there is an {*word*118} problem with a non-obvious solution.
I'm keeping a copy of that one!
Pretty much everything in Windows is represented by ITEMIDLIST and
IShellFolder, especially virtual/special folders that don't have physical
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
 

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
 

Re:FindFirst vs. PIDL

Thanks for the link Mehmet
Combined with what Remy provided I think I got it now.
Kind regards
Asger