Jump to content
Sign in to follow this  

how can get Type for file

Recommended Posts


how can get Type of file like

(pagefile.sys is System)

(1.txt is Text Document)

Share this post

Link to post
Share on other sites

#cs ----------------------------------------------------------------------------

    AutoIt Version:
    Author:         KaFu

    Script Function:

#ce ----------------------------------------------------------------------------

; http://www.autoitscript.com/forum/index.php?showtopic=105984

; http://msdn.microsoft.com/en-us/library/bb762179(VS.85).aspx

$tagSHFILEINFO = 'int hIcon;int iIcon;dword Attributes;wchar DisplayName[260];wchar TypeName[80]'

Global Const $SHGFI_ATTR_SPECIFIED = 0x00020000
Global Const $SHGFI_ATTRIBUTES = 0x00000800
Global Const $SHGFI_DISPLAYNAME = 0x00000200
Global Const $SHGFI_EXETYPE = 0x00002000
Global Const $SHGFI_ICON = 0x00000100
Global Const $SHGFI_ICONLOCATION = 0x00001000
Global Const $SHGFI_LARGEICON = 0x00000000
Global Const $SHGFI_LINKOVERLAY = 0x00008000
Global Const $SHGFI_OPENICON = 0x00000002
Global Const $SHGFI_OVERLAYINDEX = 0x00000040
Global Const $SHGFI_PIDL = 0x00000008
Global Const $SHGFI_SELECTED = 0x00010000
Global Const $SHGFI_SHELLICONSIZE = 0x00000004
Global Const $SHGFI_SMALLICON = 0x00000001
Global Const $SHGFI_SYSICONINDEX = 0x00004000
Global Const $SHGFI_TYPENAME = 0x00000400
Global Const $SHGFI_USEFILEATTRIBUTES = 0x00000010

Global Const $dwFILE_ATTRIBUTE_NORMAL = 0x80

$bFirstExtFound = False ; first key in my reg does NOT start with '.' but with '!', that's why to search for first '.' found
$i = 1 ; counter for reg key enumeration
while 1
    $sExtensionFromReg = RegEnumKey('HKCR\', $i) ; enum possible extensions from registry
    if @error then exitloop
    if StringLeft($sExtensionFromReg, 1) <> '.' AND $bFirstExtFound = True then ExitLoop ; last extension found in reg, exitloop
    if StringLeft($sExtensionFromReg, 1) = '.' then
        $bFirstExtFound = True
        ConsoleWrite($sExtensionFromReg & @tab & " => " & @tab & _WinAPI_ShellGetFileInfo_TYPENAME($sExtensionFromReg,BitOR($SHGFI_USEFILEATTRIBUTES,$SHGFI_TYPENAME)) & @crlf)
    $i += 1

Func _WinAPI_ShellGetFileInfo_TYPENAME($sPath, $iFlags, $iAttributes = 0x80)
    Local $tSHFILEINFO = DllStructCreate($tagSHFILEINFO)
    Local $Ret = DllCall('shell32.dll', 'ptr', 'SHGetFileInfoW', 'wstr', $sPath, 'dword', $iAttributes, 'ptr', DllStructGetPtr($tSHFILEINFO), 'int', DllStructGetSize($tSHFILEINFO), 'int', $iFlags)
    If @error Then
        Return SetError(1, 0, 0)
    Return DllStructGetData($tSHFILEINFO,5)
EndFunc   ;==>_WinAPI_ShellGetFileInfo

Edited by KaFu

Share this post

Link to post
Share on other sites

ConsoleWrite(_GetFileDesc("info.txt") & @LF)

Func _GetFileDesc($sFilename)
 Local $ext = StringTrimLeft($sFilename, StringInStr($sFilename, ".", 0, -1) - 1)
 Return RegRead("HKCR" & "\" & RegRead("HKCR" & "\" & $ext, ""), "")

Programming today is a race between software engineers striving to
build bigger and better idiot-proof programs, and the Universe
trying to produce bigger and better idiots.
So far, the Universe is winning.

Share this post

Link to post
Share on other sites

well i would use a combination of

StringRegExp ( "test", "pattern" [, flag ] [, offset ] ] )

and the file name :)

Share this post

Link to post
Share on other sites


I have sometimes used the TrID utility to ID files from apps not installed on my machine - it is free and pretty accurate. You can find out about it here.


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:


ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area


Share this post

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this