Jump to content

Read/Display file content - non txt file


Go to solution Solved by mLipok,

Recommended Posts

Posted

How to view content of file (see attachment)

 

I try using fileopen / fileread / fileclose

but then I see only "–˛8Y" or binary.

 

I need something another.

 

for example

This is content which I see when I using lister from TotalCommander

  Quote

–˛8Y   P     Đ  HP LaserJet 1020                 ś 4ź           X X                                                                                          SDDM    HP LaserJet 1020                                                                                                         -                     €€€ ˙   ˙˙   ˙   ˙˙   ˙ ˙ ˙                 (   d                                                       Ţ  Ţ           €                                         Śń`4           €˙                                                                                                                                                                                                                                                                                                                                                                                                                                                   <   $ winspool  HP LaserJet 1020  USB002                       ‚.  ĆA       n  7  7  7  ®           TEST1

TEST2
TEST3
                 @       P8˙         î  Times New Roman                  
   Ŕ          d     nÜJ
¸&”p#Ţ'L,ş0(5–9>                T i m e s   N e w   R o m a n                                                   â  

 

 

How to show that in AU3 ?

I attach example file

 

TEST123.zip

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Which program did you use to display the content of the file above? Couldn't you use this program from AutoIt?

My UDFs and Tutorials:

  Reveal hidden contents

 

Posted

I use TotalCommander with internal F3 - lister

I want to take that same effect

for example

I want to check  if this file contain

 

TEST1

TEST2
TEST3

 

but Case-insensitivity

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

What parameters did you use with FileOpen?

UDF List:

  Reveal hidden contents

Updated: 22/04/2018

Posted

The binary data contains characters which can not be translated into a (ascii) string, here's a work-around...

#include <array.au3>
Local $hFile = FileOpen("TEST123.skk", 16)
If $hFile = -1 Then
MsgBox(0, "Error", "Unable to open file.")
Exit
EndIf
$sData = FileRead($hFile)
FileClose($hFile)

$sData = _HexEncode($sData, 0x00000005)
$aData = StringSplit($sData, @CRLF, 1)
; _ArrayDisplay($aData)

$sData = ""
For $i = 1 To $aData[0]
$sData &= StringRight($aData[$i], 16)
Next
MsgBox(0, "", $sData)

Func _HexEncode($bInput, $iFlags = 0x0000000b)
; CryptBinaryToString function (Windows)
; http://msdn.microsoft.com/en-us/library/windows/desktop/aa379887%28v=vs.85%29.aspx

Local $tInput = DllStructCreate("byte[" & BinaryLen($bInput) & "]")
DllStructSetData($tInput, 1, $bInput)
Local $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($tInput), _
"dword", DllStructGetSize($tInput), _
"dword", $iFlags, _
"ptr", 0, _
"dword*", 0)

If @error Or Not $a_iCall[0] Then
Return SetError(1, 0, "")
EndIf

Local $iSize = $a_iCall[5]
Local $tOut = DllStructCreate("char[" & $iSize & "]")

$a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
"ptr", DllStructGetPtr($tInput), _
"dword", DllStructGetSize($tInput), _
"dword", $iFlags, _
"ptr", DllStructGetPtr($tOut), _
"dword*", $iSize)

If @error Or Not $a_iCall[0] Then
Return SetError(2, 0, "")
EndIf

Return SetError(0, 0, DllStructGetData($tOut, 1))

EndFunc ;==>_HexEncode
Posted

Thanks KaFu

this works

but I have problem with Diacritic mark 

  Quote

–˛8Y   P     Đ  HP LaserJet 1020                 ś 4ź         X X                                                                                          SDDM    HP LaserJet 1020                                                                                                         -                     €€€ ˙   ˙˙   ˙   ˙˙   ˙ ˙ ˙                 (   d                                                       Ţ  Ţ           €                                         Śń`4           €˙                                                                                                                                                                                                                                                                                                                                                                                                                                                   <   $ winspool  HP LaserJet 1020  USB002                       ‚.  ĆA       n  7  7  7  ®         !   Polish Diacritic mark: ąćęłńóśżź

            !      @       P8˙         î  Times New Roman                 ! " "  Ŕ          d     nÜJ
¸&”p#Ţ'L,ş0(5–9>                T i m e s   N e w   R o m a n                                                   â  

 

 

in TotalCommander there is 

Polish Diacritic mark: ąćęłńóśżź

 

 

result _HexEncode(..

Polish Diacritic mark: ..........

 

 

  Quote
..8Y....P...........HP LaserJet 1020......................4...................X.....X...........................................................................................SDDM........HP LaserJet 1020........................................................................................................................................................-...................................................................(...d......................................................................................................................`4...................................................................................................................................................................................................................................................................................................................................................................................................................................................................<.......$...winspool..HP LaserJet 1020..USB002...............................A..........n...7...7...7.................!...Polish Diacritic mark: .....................................!......@.......P8.................Times New Roman.....................!...".".............d. ......n.....J.....&........p#..'.L,..0.(5..9..>................T.i.m.e.s. .N.e.w. .R.o.m.a.n.........................................  ..............

 

 

 

 

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

oh..

I forgot to attach new file

TEST123_Polish.zip

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Intresting

When I open TEST123_Polish.skk in Scite 

then I see diffrent data (in comparision to TotalCommander - Lister )

but "Polish Diacritic mark: ąćęłńóśżź" is correctly displayed

 

  Quote

–˛8Y   P     Đ  HP LaserJet 1020                 ś 4ź         X X                                                                                          SDDM    HP LaserJet 1020                                                                                                         -                     €€€ ˙   ˙˙   ˙   ˙˙   ˙ ˙ ˙                 (   d                                                       Ţ  Ţ           €                                         Śń`4           €˙                                                                                                                                                                                                                                                                                                                                                                                                                                                   <   $ winspool  HP LaserJet 1020  USB002                       ‚.  ĆA       n  7  7  7  ®         !   Polish Diacritic mark: ąćęłńóśżź

            !      @       P8˙         î  Times New Roman                 ! " "  Ŕ          d     nÜJ
¸&”p#Ţ'L,ş0(5–9>                T i m e s   N e w   R o m a n                                                   â  

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

Is this displaying it properly for you?

#include <WinAPI.au3>
#include <array.au3>
Global Enum $CRYPT_STRING_BASE64HEADER = 0, $CRYPT_STRING_BASE64, $CRYPT_STRING_BINARY, $CRYPT_STRING_BASE64REQUESTHEADER, $CRYPT_STRING_HEX, _
            $CRYPT_STRING_HEXASCII
Global Enum $CRYPT_STRING_BASE64X509CRLHEADER = 9, $CRYPT_STRING_HEXADDR, $CRYPT_STRING_HEXASCIIADDR, $CRYPT_STRING_HEXRAW
Global Const $CRYPT_STRING_STRICT = 0x20000000, $CRYPT_STRING_NOCRLF = 0x40000000, $CRYPT_STRING_NOCR = 0x80000000

Local $hFile = FileOpen("TEST123_Polish.skk", 16)
If $hFile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$sData = FileRead($hFile)
FileClose($hFile)

$sData = _WinAPI_CryptBinaryToString($sData, $CRYPT_STRING_HEXRAW)
$aData = StringSplit($sData, @CRLF, 1)
$aData = StringRegExp($aData[1], ".{2}", 3)
;~ _ArrayDisplay($aData)

$sData = ""
For $i = 1 To UBound($aData) - 1
    $sData &= _WinAPI_MultiByteToWideChar(ChrW(Dec($aData[$i])), 3, 0, 1)
Next
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sData = ' & $sData & @crlf) ;### Debug Console
MsgBox(0, "Test", $sData)


Func _WinAPI_CryptBinaryToString($bInput, $iFlags = 0x0000000b)
    ; CryptBinaryToString function (Windows)
    ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa379887(v=vs.85).aspx

    Local $tInput = DllStructCreate("byte[" & BinaryLen($bInput) & "]")
    DllStructSetData($tInput, 1, $bInput)
    Local $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
                                                    "struct*", $tInput, _
                                                    "dword", DllStructGetSize($tInput), _
                                                    "dword", $iFlags, _
                                                    "ptr", 0, _
                                                    "dword*", 0)

    If @error Or Not $a_iCall[0] Then
        Return SetError(1, 0, "")
    EndIf

    Local $iSize = $a_iCall[5]
    Local $tOut = DllStructCreate("char[" & $iSize & "]")

    $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
                                             "struct*", $tInput, _
                                             "dword", DllStructGetSize($tInput), _
                                             "dword", $iFlags, _
                                             "struct*", $tOut, _
                                             "dword*", $iSize)

    If @error Or Not $a_iCall[0] Then
        Return SetError(2, 0, "")
    EndIf

    Return SetError(0, 0, DllStructGetData($tOut, 1))

EndFunc   ;==>_HexEncode

Br,

UEZ

Edited by UEZ

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Posted

Better, but not up to the end

  Quote

28YP?HP LaserJet 1020?4? XXSDDMHP LaserJet 1020 -???yyyyyyyyy(d????n`4?y<$winspoolHP LaserJet 1020USB002?.AAn777®!Polish Diacritic mark: 1ae3nó???

!@P8yîTimes New Roman!""Ad nÜJ
¸&?p#?'L,o0(5?9>Times New Romanâ

 

 

Polish Diacritic mark: 1ae3nó???

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

I found it

$sData &= _WinAPI_MultiByteToWideChar(Chr(Dec($aData[$i])), 1250, 0, True)

there was ChrW 

but

this must be 

Chr

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

  • Solution
Posted (edited)

Complete script

#include <WinAPI.au3>
#include <array.au3>
Global Enum $CRYPT_STRING_BASE64HEADER = 0, $CRYPT_STRING_BASE64, $CRYPT_STRING_BINARY, $CRYPT_STRING_BASE64REQUESTHEADER, $CRYPT_STRING_HEX, _
        $CRYPT_STRING_HEXASCII
Global Enum $CRYPT_STRING_BASE64X509CRLHEADER = 9, $CRYPT_STRING_HEXADDR, $CRYPT_STRING_HEXASCIIADDR, $CRYPT_STRING_HEXRAW
Global Const $CRYPT_STRING_STRICT = 0x20000000, $CRYPT_STRING_NOCRLF = 0x40000000, $CRYPT_STRING_NOCR = 0x80000000

Local $hFile = FileOpen("TEST123_Polish.skk", 16)
If $hFile = -1 Then
    MsgBox(0, "Error", "Unable to open file.")
    Exit
EndIf
$sData = FileRead($hFile)
FileClose($hFile)

$sData = _WinAPI_CryptBinaryToString($sData, $CRYPT_STRING_HEXRAW)
$aData = StringSplit($sData, @CRLF, 1)
$aData = StringRegExp($aData[1], ".{2}", 3)
;~ _ArrayDisplay($aData)

$sData = ""
For $i = 1 To UBound($aData) - 1
    $sData &= _WinAPI_MultiByteToWideChar(Chr(Dec($aData[$i])), 1250, 0, 1)
Next
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sData = ' & $sData & @CRLF) ;### Debug Console
MsgBox(0, "Test", $sData)


Func _WinAPI_CryptBinaryToString($bInput, $iFlags = 0x0000000b)
    ; CryptBinaryToString function (Windows)
    ; http://msdn.microsoft.com/en-us/library/windows/desktop/aa379887(v=vs.85).aspx

    Local $tInput = DllStructCreate("byte[" & BinaryLen($bInput) & "]")
    DllStructSetData($tInput, 1, $bInput)
    Local $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
            "struct*", $tInput, _
            "dword", DllStructGetSize($tInput), _
            "dword", $iFlags, _
            "ptr", 0, _
            "dword*", 0)

    If @error Or Not $a_iCall[0] Then
        Return SetError(1, 0, "")
    EndIf

    Local $iSize = $a_iCall[5]
    Local $tOut = DllStructCreate("char[" & $iSize & "]")

    $a_iCall = DllCall("crypt32.dll", "int", "CryptBinaryToString", _
            "struct*", $tInput, _
            "dword", DllStructGetSize($tInput), _
            "dword", $iFlags, _
            "struct*", $tOut, _
            "dword*", $iSize)

    If @error Or Not $a_iCall[0] Then
        Return SetError(2, 0, "")
    EndIf

    Return SetError(0, 0, DllStructGetData($tOut, 1))
EndFunc   ;==>_WinAPI_CryptBinaryToString

EDIT:

and BIG thanks goes to UEZ and KaFu

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted

now results is that:

Polish Diacritic mark: ąćęłńóśżź

 

  Quote

–˛8YPĐHP LaserJet 1020ś4ź XXSDDMHP LaserJet 1020 -€€€˙˙˙˙˙˙˙˙˙(dŢŢ€Śń`4€˙<$winspoolHP LaserJet 1020USB002‚.ĆAn777®!Polish Diacritic mark: ąćęłńóśżź

!@P8˙îTimes New Roman!""Ŕd nÜJ
¸&”p#Ţ'L,ş0(5–9>Times New Romanâ

 

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

Posted (edited)

ps.

I hope that it will not be offended UEZ and KaFu for it that I have meant my post as BEST ANSWER

I do that for other members to mark complete solutions 

I write about it as, does not have established principles for this new function "BEST ANSWER"

Edited by mlipok

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

  Reveal hidden contents

Signature last update: 2023-04-24

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...