Jump to content

Recommended Posts

Posted

I use this to convert a file in binary mode.

$File_Handle = FileOpen($File_Path, 0+16)

$File_Content = FileRead($File_Handle)

FileClose($File_Handle)

FileWrite("prova.txt", $File_Content)

How can I convert the new file (in this case, prova.txt) back to the original file?

Thanks for help

  • Moderators
Posted

FSoft,

Just open the new file for binary writing: ;)

$File_Path = "fred4.au3"

$File_Handle = FileOpen($File_Path, 0 + 16)
$File_Content = FileRead($File_Handle)
FileClose($File_Handle)

ConsoleWrite($File_Content & @CRLF)

FileWrite("prova.txt", $File_Content)

$File_Handle = FileOpen("Original.txt", 2 + 16)
FileWrite($File_Handle, $File_Content)
FileClose($File_Handle)

But have you looked at what is in prova.txt? :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

@Melba: Thank you for your reply, but you don't understand what I'm trying to do.

I have the following script:

$File_Path = "test.zip"
$File_Handle = FileOpen($File_Path, 0+16)
$File_Content = FileRead($File_Handle)
FileClose($File_Handle)
FileWrite("prova.txt", $File_Content)
Exit

The file "prova.txt" contains the binary version of the file "test.zip".

Now I want another script to open the file "prova.txt" and convert it back to "test.zip". It's possible to do this?

Thank you for help!

Edited by FSoft
Posted

Hey!! FSoft

Nice Meeting U

Maybe This is the UDF that will Do Your Work

Link:

Thumbs Up if it Helped ;)

Regards

Phoenix XL

My code:

  Reveal hidden contents
PredictText: Predict Text of an Edit Control Like Scite. Remote Gmail: Execute your Scripts through Gmail. StringRegExp:Share and learn RegExp.

Run As System: A command line wrapper around PSEXEC.exe to execute your apps scripts as System (LSA). Database: An easier approach for _SQ_LITE beginners.

MathsEx: A UDF for Fractions and LCM, GCF/HCF. FloatingText: An UDF for make your text floating. Clipboard Extendor: A clipboard monitoring tool. 

Custom ScrollBar: Scroll Bar made with GDI+, user can use bitmaps instead. RestrictEdit_SRE: Restrict text in an Edit Control through a Regular Expression.

Posted (edited)

Hi Phoenix. Thank you for the answer, however that script uses encbin and decbin to do the work. I don't want to rely on 3rd part components.

It's possible to do everything in pure AutoIt?

Edited by FSoft
Posted

I don't really understand. You have a binary file, and write it as Hex-encoded string in a new file. Now you are looking for a way to convert this string back into a binary file?

; read binary file
$hFile = FileOpen($sBinaryFile, 16)
$bBinary = FileRead($hFile)
FileClose($hFile)

; write hex file
$hFile = FileOpen($sStringFile, 2)
FileWrite($hFile, String($sBinary))
FileClose($hFile)

; --------------------------------------

; read hex file
$hFile = FileOpen($sStringFile)
$sString = FileRead($hFile)
FileClose($hFile)

; write new binary file
$hFile = FileOpen($sNewBinaryFile, 18)
FileWrite($hFile, Binary($sString))
FileClose($hFile)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Posted

  On 5/7/2012 at 8:55 AM, 'Filarono said:

@ProgAndy: That doesn't work. I tried with a PDF and the new file created is corrupted.

There was a small typo. This works for me:
$sBinaryFile = "test.png"
$sStringFile = "testbin.txt"
$sNewBinaryFile = "test_out.png"

; read binary file
$hFile = FileOpen($sBinaryFile, 16)
$bBinary = FileRead($hFile)
FileClose($hFile)

; write hex file
$hFile = FileOpen($sStringFile, 2)
FileWrite($hFile, String($bBinary))
FileClose($hFile)

; --------------------------------------

; read hex file
$hFile = FileOpen($sStringFile)
$sString = FileRead($hFile)
FileClose($hFile)

; write new binary file
$hFile = FileOpen($sNewBinaryFile, 18)
FileWrite($hFile, Binary($sString))
FileClose($hFile)

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

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...