Page 1 of 1

Getting file type

Posted: Sun Oct 16, 2005 7:14 pm
by Polo
Hi !
I've got something I would like to do : In Explorer, we can get specific file type, like :
Image
How can I get this type in Purebasic ?
Thanks !
Gaetan

Posted: Sun Oct 16, 2005 7:56 pm
by freak

Code: Select all

File$ = OpenFileRequester("Choose File...", "", "All Files (*.*)|*.*", 0)

If File$ <> ""

  If SHGetFileInfo_(@File$, 0, @info.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_TYPENAME)
  
    Debug PeekS(@info\szTypeName[0], 80)
  
  EndIf
  
  
EndIf

Posted: Sun Oct 16, 2005 8:02 pm
by roachofdeath
Doh, you beat me to it freak ;)

If you want to do it the long way, find the extention in the registry, and get the (Default) value of it. Then search for the default value in the registry, and there will be the file type.

Posted: Sun Oct 16, 2005 8:07 pm
by Polo
freak wrote:

Code: Select all

File$ = OpenFileRequester("Choose File...", "", "All Files (*.*)|*.*", 0)

If File$ <> ""

  If SHGetFileInfo_(@File$, 0, @info.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_TYPENAME)
  
    Debug PeekS(@info\szTypeName[0], 80)
  
  EndIf
  
  
EndIf
Perfect and fast answer, I love you :lol: 8)

Posted: Sun Oct 16, 2005 8:10 pm
by Polo
Maybe do you know also where to get the icon associated to the type ? That would help me a lot too :)
8)

Posted: Sun Oct 16, 2005 8:21 pm
by freak
It can all be done with this function. Just see the possible flags options here:
http://msdn.microsoft.com/library/defau ... leinfo.asp

for the icon:

Code: Select all

File$ = OpenFileRequester("Choose File...", "", "All Files (*.*)|*.*", 0)
If File$ <> ""
  If SHGetFileInfo_(@File$, 0, @info.SHFILEINFO, SizeOf(SHFILEINFO), #SHGFI_ICON|#SHGFI_LARGEICON)
  
    ; Icon handle is returned here:
    Debug info\hIcon
    
    ; if you want a PB image:
    CreateImage(1, 32, 32)
    If StartDrawing(ImageOutput())
      DrawImage(info\hIcon, 0, 0)
    EndIf
    
    ; free icon when no longer needed:
    DestroyIcon_(info\hIcon)
  
  EndIf
EndIf
There is also a flag to get the small icon...

Posted: Sun Oct 16, 2005 8:48 pm
by Polo
Thanks again, it works really well !!