ken82m Posted January 7, 2009 Share Posted January 7, 2009 (edited) Does anyone know how I can check the real file type regardless of extension. For example I could rename an XLS file to TXT. Is their a way to verify that's it's not really a plain text file? I thought there was an IsAlpha() function but I don't see it in the help file. In this case all I care about is making sure it's plain text, but it would be useful to be able to check content types in general. Thanks, Kenny Edited January 7, 2009 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
ken82m Posted January 7, 2009 Author Share Posted January 7, 2009 (edited) ahh I found it in another post it was StringIsAlpha() I ran a search in the help file for IsAlpha but no luck. Thanks anyway, Kenny Edited January 7, 2009 by ken82m "I believe that when we leave a place, part of it goes with us and part of us remains... Go anywhere, when it is quiet, and just listen.. After a while, you will hear the echoes of all our conversations, every thought and word we've exchanged.... Long after we are gone our voices will linger in these walls for as long as this place remains." Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 7, 2009 Share Posted January 7, 2009 I also would like to know a way to extract file-type from the file itself... Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
weaponx Posted January 7, 2009 Share Posted January 7, 2009 Here is an example in C#:http://www.codeproject.com/KB/files/FindMimeFromData.aspx Link to comment Share on other sites More sharing options...
weaponx Posted January 8, 2009 Share Posted January 8, 2009 I found this program call TrID as well, not sure if it works. Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 8, 2009 Share Posted January 8, 2009 All those programs is good, but we need something on AutoIt ... That C# example, could be translated to AutoIt? via WinAPI perhaps? or what it uses... Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
smashly Posted January 8, 2009 Share Posted January 8, 2009 Get the signature of the different file types and store them to compare. Open the file you want to check in binary mode and read some of the starting bytes to get the signature and compare against the stored signatures.. That's what I was doing for exe, pdf, ico, mp3, rar.. etc. But I notice that not all file types have a signature.. Link to comment Share on other sites More sharing options...
weaponx Posted January 8, 2009 Share Posted January 8, 2009 TrID offers a dll library. Look at the first language mentioned in the example list (hint - its AutoIt):http://mark0.net/code-tridlib-e.html Link to comment Share on other sites More sharing options...
MrCreatoR Posted January 8, 2009 Share Posted January 8, 2009 TrID offers a dll library. Look at the first language mentioned in the example list (hint - its AutoIt):http://mark0.net/code-tridlib-e.htmlNice, but it's too mch (1+ mb) to use it for such litle task But thanks anyway, it's a start... Spoiler Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1 AutoIt Russian Community My Work... Spoiler Projects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize ProgramUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF Examples: ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating ) * === My topics === * ================================================== ================================================== AutoIt is simple, subtle, elegant. © AutoIt Team Link to comment Share on other sites More sharing options...
weaponx Posted January 8, 2009 Share Posted January 8, 2009 Nice, but it's too mch (1+ mb) to use it for such litle task But thanks anyway, it's a start...Are you crazy? Its not a trivial task at all. The definition file can identify 3,640 different file types, I think 1.4 Mb is small for how many signatures it contains. Link to comment Share on other sites More sharing options...
KaFu Posted January 8, 2009 Share Posted January 8, 2009 I think 1.4 Mb is small for how many signatures it contains.Eh? Did i miss something? I just see a 19 KB dll file? Which download are you talking about? Anyway, thinks this will be a nice addition to SMF ....Regards OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
weaponx Posted January 8, 2009 Share Posted January 8, 2009 (edited) Eh? Did i miss something? I just see a 19 KB dll file? Which download are you talking about? Anyway, thinks this will be a nice addition to SMF .... Regards You need the definition file which is a database of file type signatures. Look at the script example: expandcollapse popup; TrIDlib AutoIt Demo ; http://mark0.net/code-tridlib-e.html #include "TrIDLib-const.au3" $MyFile = "triddefs.trd" ; a random file to analyze $Buf = "" ; allocate a string for the results $Dll = DllOpen("TrIDLib.DLL") ; Open TrIDLib DLL $Ret = DllCall($Dll, "int", "TrID_LoadDefsPack", "str", "") ; load the definitions $Ret = DllCall($Dll, "int", "TrID_SubmitFileA", "str", $MyFile) ; submit the file $Ret = DllCall($Dll, "int", "TrID_Analyze") ; perform the analysis if @error = 1 then MsgBox(48, "TrID_Analyze", "Error(s) occurred!") Else $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_NUM, "int", 0, "str", $Buf) $ResNum = $Ret[0] ; get the results number $Out = "" if $ResNum = 0 Then $Out = "Unknown filetype!" Else For $ResId = 1 to $ResNUm ; cycle trough results $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_FILETYPE, "int", $ResId, "str", $Buf) $Out = $Out & $ResId & ":" & Chr(9) & $Ret[3] ; get the filetype description $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_FILEEXT, "int", $ResId, "str", $Buf) $Out = $Out & " (" & $Ret[3] & ")" ; get the filetype extension $Ret = DllCall($Dll, "int", "TrID_GetInfo", "int", $TRID_GET_RES_POINTS, "int", $ResId, "str", $Buf) $Out = $Out & " - " & $Ret[0] ; get the matching points $Out = $Out & Chr(13) Next EndIf MsgBox(0, "TrIDLib demo", $Out) EndIf DllClose($Dll) ; cleanup Edited January 8, 2009 by weaponx Link to comment Share on other sites More sharing options...
KaFu Posted January 8, 2009 Share Posted January 8, 2009 You need the definition file which is a database of file type signatures.Ah, i see, got the demo working... nice find m8 , and compressed 440 kb is worth the bandwidth , will integrate it in SMF Best Regards OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
weaponx Posted January 8, 2009 Share Posted January 8, 2009 Strangely it always returns "Unknown filetype!" for a simple text or zip file in AutoIt 3.3.0.0 Link to comment Share on other sites More sharing options...
KaFu Posted January 8, 2009 Share Posted January 8, 2009 (edited) Strangely it always returns "Unknown filetype!" for a simple text or zip file in AutoIt 3.3.0.0Works for me, identifies zip... had an error in the first try though... zip file was 0 Bytes large, that returned an unkown ... but you're right bout the txt file. I guess the reason is, that a plain txt file has no unique signature... Edited January 8, 2009 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2022-Nov-26) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Feb-16) HMW - Hide my Windows (2018-Sep-16) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2023-Jun-03) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16) Link to comment Share on other sites More sharing options...
weaponx Posted January 8, 2009 Share Posted January 8, 2009 Works for me, identifies zip... had an error in the first try though... zip file was 0 Bytes large, that returned an unkown ... but you're right bout the txt file. I guess the reason is, that a plain txt file has no unique signature...I think you're right. I tried an empty zip file first, it works when not empty. Also if you save the text file as UTF-8 it is recognized. 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