Getting file type

Just starting out? Need help? Post your questions and find answers here.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Getting file type

Post 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
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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
quidquid Latine dictum sit altum videtur
roachofdeath
User
User
Posts: 78
Joined: Sun Apr 24, 2005 3:22 am

Post 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.
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post 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)
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Maybe do you know also where to get the icon associated to the type ? That would help me a lot too :)
8)
freak
PureBasic Team
PureBasic Team
Posts: 5940
Joined: Fri Apr 25, 2003 5:21 pm
Location: Germany

Post 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...
quidquid Latine dictum sit altum videtur
Polo
Addict
Addict
Posts: 2422
Joined: Tue May 06, 2003 5:07 pm
Location: UK

Post by Polo »

Thanks again, it works really well !!
Post Reply