Question on SHGetFileInfo
Code:
SHGetFileInfo(Path.c_str(), 0, &SHFileInfo, sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
The above function will examine the file referenced by Path and return me information on it, such as its system image list index, (which is appropriately a folder if a directory, or a file association icon if it is a file).
I have tried testing SHFILEINFO::dwAttributes for SFGAO_FOLDER to see if this item is a folder or not, but this does not work!
I need to know how I can determine if a file referenced by SHGetFileInfo is a directory or not.
I'm making my list view so that if a user double clicks a folder, they will get a list of subdirectories of that folder. The reason why I need to test to see if the double clicked item is a folder, is because you can't list sub directories for a file now can you? If the user double clicks a file, you open it... not list its subdirectories!
Below is more code. Sorry if you don't understand something, but I use a lot of my own data structures in this sample. You should get the basic idea:
Code:
SHGetFileInfo(Path.c_str(), 0, &SHFileInfo, sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
if(SHFileInfo.dwAttributes & SFGAO_FOLDER)
{
NewItemInfo.Directory = true;
}
else
NewItemInfo.Directory = false;
Thanks for any and all help!
Re: Question on SHGetFileInfo
First define
CString strFileName = (LPCTSTR) &fd.cFileName;
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((strFileName != ".") && (strFileName != ".."))
{
//Do something
}
}
Look in winnt.h for #define FILE_ATTRIBUTE_DIRECTORY
Re: Question on SHGetFileInfo
Replace
Code:
if(SHFileInfo.dwAttributes & SFGAO_FOLDER)
with
Code:
if(SHFileInfo.dwAttributes & FILE_ATTRIBUTE_DIRECTORY)
Re: Question on SHGetFileInfo
Quote:
Originally Posted by maggiemay
First define
CString strFileName = (LPCTSTR) &fd.cFileName;
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if ((strFileName != ".") && (strFileName != ".."))
{
//Do something
}
}
Well...what is 'fd' in this example? There is no 'fd' in the original question...
Re: Question on SHGetFileInfo
Thank you Andreas.
I think this is interesting because MSDN suggests to use the SFGAO_ flags with dwAttributes. It says nothing about using the flags you have shown me.
I guess these are reasons why people can't rely on MSDN 100% of the time :(
Re: Question on SHGetFileInfo
Well I just applied the changes, and it still doesn't work.
Here is an update:
Code:
SHGetFileInfo(Path.c_str(), 0, &SHFileInfo, sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON);
if(SHFileInfo.dwAttributes & FILE_ATTRIBUTE_DIRECTORY)
NewItemInfo.Directory = true;
else
NewItemInfo.Directory = false;
Re: Question on SHGetFileInfo
Well, actually my problem was not adding the SHGFI_ATTRIBUTES flag to my SHGetFileInfo function.
Here is the working copy:
Code:
SHGetFileInfo(Path.c_str(), 0, &SHFileInfo, sizeof(SHFILEINFO),
SHGFI_SYSICONINDEX | SHGFI_SMALLICON | SHGFI_ATTRIBUTES);
if(SHFileInfo.dwAttributes & SFGAO_FOLDER)
NewItemInfo.Directory = true;
else
NewItemInfo.Directory = false;
Re: Question on SHGetFileInfo
Oh Sorry I misundstood the ? I am sorry to have bothered you,
Best Wieshes,
Re: Question on SHGetFileInfo
Don't be sorry Maggie, I appreciate your time, no matter how you answer!
Re: Question on SHGetFileInfo
Quote:
Originally Posted by MrDoomMaster
I think this is interesting because MSDN suggests to use the SFGAO_ flags with dwAttributes. It says nothing about using the flags you have shown me.
Well...it mentions
Quote:
Originally Posted by MSDN
dwFileAttributes
[in] Combination of one or more file attribute flags (FILE_ATTRIBUTE_ values as defined in Winnt.h). If uFlags does not include the SHGFI_USEFILEATTRIBUTES flag, this parameter is ignored.
Re: Question on SHGetFileInfo
It suggests to use FILE_ATTRIBUTE_ with the SHGetFileInfo function's dwAttributes parameter.
The parameter right after this one requires a SHFILEINFO structure, which is where you obtain all of the information about the file. This structure also contains a dwAttributes.
Here is MSDN's description of the dwAttributes member of the SHFILEINFO structure:
dwAttributes
Array of values that indicates the attributes of the file object. For information about these values, see the IShellFolder::GetAttributesOf method.
Re: Question on SHGetFileInfo
Whops...sorry, did not realize that you were working with the attribute within the structure....sorry for the confusion I added... :blush: