michaelslamet Posted April 7, 2014 Posted April 7, 2014 How to check if a file is a text file or a binary file without see the file extension? Binary example: doc, swf, exe, zip, rar, jpg, png, gif Text example: txt, xml, ini, inf, log Thanks
Solution KaFu Posted April 7, 2014 Solution Posted April 7, 2014 http://mark0.net/code-tridlib-e.html BrewManNH and michaelslamet 2 OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
michaelslamet Posted April 8, 2014 Author Posted April 8, 2014 http://mark0.net/code-tridlib-e.html Looks promising, especially this library also used in SMF! thanks! Unfortunetely, no matter what file I put to analyzed, it always display: "Unknown filetype!" expandcollapse popup; TrIDlib AutoIt Demo ; http://mark0.net/code-tridlib-e.html #include "TrIDLib-const.au3" $MyFile = "c:\temp\11.jpg" ; 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 WinXP, AutoIT 3.8.8.1 What did I do wrong?
KaFu Posted April 8, 2014 Posted April 8, 2014 (edited) I guess you did not download the TrIDDefs.TRD package from here: http://mark0.net/soft-trid.html] Edited April 8, 2014 by KaFu OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
michaelslamet Posted April 8, 2014 Author Posted April 8, 2014 I guess you did not download the TrIDDefs.TRD package from here: http://mark0.net/soft-trid.html TrId.zip Thank you again, KaFu. You're correct Now it's working to .jpg and .exe files, but when it come to text file (.txt, .au3) why it always return "Unknown filetype!" ? Test and see yourself
KaFu Posted April 8, 2014 Posted April 8, 2014 In SMF I replaced "unkown" with "Indeterminable (e.g. text-file) / unknown filetype". There is nothing unique about a txt file, except from the extension it could also be an .au3 file, an .html file or a .py file... TrID is looking for file specific patterns / headers (jpg, zip, exe), but txt files just don't have these kind of patterns. OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
michaelslamet Posted April 8, 2014 Author Posted April 8, 2014 In SMF I replaced "unkown" with "Indeterminable (e.g. text-file) / unknown filetype". There is nothing unique about a txt file, except from the extension it could also be an .au3 file, an .html file or a .py file... TrID is looking for file specific patterns / headers (jpg, zip, exe), but txt files just don't have these kind of patterns. aha! understand now So could I say if it is detected as "unknown", it's quite a big chance it's a text file? Not 100% for sure, but pretty big chance?
KaFu Posted April 8, 2014 Posted April 8, 2014 Hmmm, yes, I would think so, not 100% for sure, but pretty big chance is a good summary ... OS: Win10-22H2 - 64bit - German, AutoIt Version: 3.3.16.1, AutoIt Editor: SciTE, Website: https://funk.eu AMT - Auto-Movie-Thumbnailer (2024-Oct-13) BIC - Batch-Image-Cropper (2023-Apr-01) COP - Color Picker (2009-May-21) DCS - Dynamic Cursor Selector (2024-Oct-13) HMW - Hide my Windows (2024-Oct-19) HRC - HotKey Resolution Changer (2012-May-16) ICU - Icon Configuration Utility (2018-Sep-16) SMF - Search my Files (2025-May-18) - THE file info and duplicates search tool SSD - Set Sound Device (2017-Sep-16)
michaelslamet Posted April 8, 2014 Author Posted April 8, 2014 Hmmm, yes, I would think so, not 100% for sure, but pretty big chance is a good summary ... Ok, I'm going to do some experiment with it. Thanks, KaFu
aVen9er Posted October 28, 2018 Posted October 28, 2018 Func FileIsBinary($nazwa_pliku) Local $iMaxLiczbaZnakow = 100 If Not FileExists($nazwa_pliku) Then Return -1 Local $iFile = FileOpen($nazwa_pliku) Local $strZaw = FileRead($iFile, $iMaxLiczbaZnakow) FileClose($iFile) Return IsBinary($strZaw) EndFunc
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