A VERY MUCH used function in my "Browse For Folder" sysTreeView
This function is ONE OF THE TOP MOST repeated and used function in my "Browse For Folder" UserControl so I felt a "guilt" to share it you all ;)
Because it's so handy och usable ;)
BUT be aware!! IF YOU is not confortable with Shell/COM programming or a beginner/novice I DO recommend YOU NOT use this function.
Code:
Public Function IsShellItemFolder(pISI As IShellItem) As Boolean
'Long value for the bit wise attribute(s) you request(s)
Dim dwAttribs As Long
'The COM return result
Dim hr As Long
'Better to be safe than sorry - quit the function if IShellItem object not was set.
If pISI Is Nothing Then Exit Function
'Initialize Function to False - Ensure no old usage is left in the memory.
IsShellItemFolder = False
'Ask for attribute(s) and return the attributes wanted.
hr = pISI.GetAttributes(SFGAO_FOLDER, dwAttribs)
'If the method returned OK - Why shouldn't it?
If hr = S_OK Then
'Ask your "out pointer" if there is/are the request(ed) attributes in the "out pointer"
If (dwAttribs And SFGAO_FOLDER) Then
'If your query match the out pointer - return True
IsShellItemFolder = True
End If
Else
'OPTIONAL - Here you can make an output/notification to the user that the method in one way or another didn't returned OK.
'Error codes are ONLY in Hexadecimal valus for COM related errors so use Hex(hr) to find out the error code.
End If
End Function
You do it best in to put this function into a class module so you don't have to write the function over and over again and just call it when needed...Like this:
Code:
Dim m_cShell32 As New cShell32 '<---- Put this Public/Global
Dim bIsFolder As Boolean
bIsFolder = m_cShell32.IsShellItemFolder(pISI_Enum)
HINT - You can switch out the SFGAO_FOLDER with whatever SFGAO_Flag(s) you whish.
Re: A VERY MUCH used function in my "Browse For Folder" sysTreeView
FYI your code will return True for .zip and .cab. If you wish to distinguish, you also need to examine SFGAO_STREAM. .zip/.cab has it, true folders do not.
Code:
pShelllItem.GetAttributes SFGAO_FOLDER Or SFGAO_STREAM, dwAtr
If (dwAtr And SFGAO_FOLDER) = SFGAO_FOLDER Then
If (dwAtr Or SFGAO_STREAM) = SFGAO_STREAM Then
'zip file
Else
'true folder
End If
End If
'or
If ((dwAtr And SFGAO_FOLDER) = SFGAO_FOLDER) And ((dwAtr And SFGAO_STREAM) = 0) Then
'True folder, not zip or cab
End If
Re: A VERY MUCH used function in my "Browse For Folder" sysTreeView
Aha, thats why I get zip-files in my tree :)
Thanks dude ;)
Re: A VERY MUCH used function in my "Browse For Folder" sysTreeView
They can be browsed with shell interfaces though, if you wanted to leave it. It's even possible to show icons with SHGetFileInfo PIDL-based queries.
When you start use shell property interfaces, it will even provide zip-specific default columns like Explorer:
https://www.vbforums.com/images/ieimages/2023/12/13.jpg