Wb-FreeKill Posted June 9, 2005 Share Posted June 9, 2005 (edited) I needed this func in my TreeViewBrowse, so i though someone may find it useful.. expandcollapse popupFunc _FileGetType($hFile) Local $hGetExt = StringRight($hFile,3) Local $hGetAttrib = FileGetAttrib($hFile) If (StringInStr($hGetAttrib,"D")) Then Return "Directory" ;/// Program files ElseIf $hGetExt = "exe" Then Return "Program" ElseIf $hGetExt = "bin" Then Return "BIN-file" ElseIf $hGetExt = "dll" Then Return "Program extension" ;/// Text files ElseIf $hGetExt = "txt" Then Return "Text-document" ElseIf $hGetExt = "au3" Then Return "AutoIt V3 Script" ElseIf $hGetExt = "RTF" Then Return "RTF-document" ElseIf $hGetExt = "htm" Then Return "HTML-document" ElseIf $hGetExt = "html" Then Return "HTML-document" ;/// Picture files ElseIf $hGetExt = "jpg" Then Return "jpg-picture" ElseIf $hGetExt = "jpeg" Then Return "jpeg-picture" ElseIf $hGetExt = "gif" Then Return "GIF-picture" ElseIf $hGetExt = "bmp" Then Return "BMP-picture" ElseIf $hGetExt = "png" Then Return "PNG-picture" ;/// Sound files ElseIf $hGetExt = "wav" Then Return "Wav-Sound" ElseIf $hGetExt = "mp3" Then Return "mp3-Sound" ;/// Packed files ElseIf $hGetExt = "rar" Then Return "RAR Archive" ElseIf $hGetExt = "zip" Then Return "ZIP Archive" ;/// Other files ElseIf $hGetExt = "url" Then Return "Internet shortcut" ElseIf $hGetExt = "chm" Then Return "Compiled HTML Help-file" ElseIf $hGetExt = "hlp" Then Return "Help-file" ElseIf $hGetExt = "pdf" Then Return "Acrobat Reader file" ;/// No match, Set Default Ext Else Return $hGetExt & "-file" EndIf EndFunc;FileGetType End Edited June 9, 2005 by Wb-FreeKill Link to comment Share on other sites More sharing options...
MHz Posted June 9, 2005 Share Posted June 9, 2005 Cool, but you know that those returns look similar to rhe default classes in registry. MsgBox(0, '', RegRead('HKEY_CLASSES_ROOT\.url', '')) This maybe an option to use also? The extention could be a variable in the regread() line? Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 9, 2005 Author Share Posted June 9, 2005 Cool, but you know that those returns look similar to rhe default classes in registry.MsgBox(0, '', RegRead('HKEY_CLASSES_ROOT\.url', ''))This maybe an option to use also? The extention could be a variable in the regread() line?<{POST_SNAPBACK}>thx, but only very few has an actual descryption, like the url.. most of them just returns "exefile,dllfile,txtfile" and so on, think mine is better but you have to code em your self Link to comment Share on other sites More sharing options...
blindwig Posted June 9, 2005 Share Posted June 9, 2005 Firstly, you're assuming that all files have an extension, and that it's always exactly 3 characters. Secondly, if you look up an extension in HCR and then look up that value, you'll usually get a better description. Observe: CODE Func _FileGetExt($sFileName) Dim $DotPos, $Other $DotPos = StringInStr($sFileName, '.', 1, -1) If $DotPos = 0 Then Return '' $Other = StringInStr($sFileName, '\', 1, -1) If $Other > $DotPos Then Return '' $Other = StringInStr($sFileName, ':', 1, -1) If $Other > $DotPos Then Return '' Return StringTrimLeft($sFileName, $DotPos) EndFunc Func _FileGetType($sFileName) Dim $Ext = _FileGetExt($sFileName), $Type, $Type2 $Type = RegRead('HKEY_CLASSES_ROOT\.' & $Ext, '') If $Type = '' Then $Type = $Ext & ' file' Else $Type2 = RegRead('HKEY_CLASSES_ROOT\' & $Type, '') If $Type2 <> '' Then $Type = $Type2 EndIf Return $Type EndFunc My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 9, 2005 Author Share Posted June 9, 2005 Func _FileGetExt($sFileName) Dim $DotPos, $Other $DotPos = StringInStr($sFileName, '.', 1, -1) If $DotPos = 0 Then Return '' $Other = StringInStr($sFileName, '\', 1, -1) If $Other > $DotPos Then Return '' $Other = StringInStr($sFileName, ':', 1, -1) If $Other > $DotPos Then Return '' Return StringTrimLeft($sFileName, $DotPos)EndFuncFunc _FileGetType($sFileName) Dim $Ext = _FileGetExt($sFileName), $Type, $Type2 $Type = RegRead('HKEY_CLASSES_ROOT\.' & $Ext, '') If $Type = '' Then $Type = $Ext & ' file' Else $Type2 = RegRead('HKEY_CLASSES_ROOT\' & $Type, '') If $Type2 <> '' Then $Type = $Type2 EndIf Return $TypeEndFuncslightly edited, now calls directories for........ directory Func _FileGetExt($sFileName) Dim $DotPos, $Other $DotPos = StringInStr($sFileName, '.', 1, -1) If $DotPos = 0 Then Return '' $Other = StringInStr($sFileName, '\', 1, -1) If $Other > $DotPos Then Return '' $Other = StringInStr($sFileName, ':', 1, -1) If $Other > $DotPos Then Return '' Return StringTrimLeft($sFileName, $DotPos) EndFunc Func _FileGetType($sFileName) Dim $Ext = _FileGetExt($sFileName), $Type, $Type2 $Type = RegRead('HKEY_CLASSES_ROOT\.' & $Ext, '') If $Type = '' Then If StringInStr(FileGetAttrib($sFileName),"D") Then $Type = "Directory" Else $Type = $Ext & '-file' EndIf Else $Type2 = RegRead('HKEY_CLASSES_ROOT\' & $Type, '') If $Type2 <> '' Then $Type = $Type2 EndIf Return $Type EndFunc Link to comment Share on other sites More sharing options...
blindwig Posted June 9, 2005 Share Posted June 9, 2005 (edited) I think you put that IF in a bad place - if you have a folder named C:\MyFolder.Txt for example, the whole directory check will be skipped. Try this instead: CODE Func _FileGetType($sFileName) Dim $Type If StringInStr(FileGetAttrib($sFileName),"D") Then $Type = RegRead('HKEY_CLASSES_ROOT\Folder', '') Else Dim $Ext = _FileGetExt($sFileName) $Type = RegRead('HKEY_CLASSES_ROOT\.' & $Ext, '') If $Type = '' Then $Type = $Ext & '-file' Else Dim $Type2 = RegRead('HKEY_CLASSES_ROOT\' & $Type, '') If $Type2 <> '' Then $Type = $Type2 EndIf EndIf Return $Type EndFunc Edited June 9, 2005 by blindwig My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions Link to comment Share on other sites More sharing options...
Wb-FreeKill Posted June 9, 2005 Author Share Posted June 9, 2005 Great thx, i think this should be included in autoit.. could be useful for some Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now