Jump to content



Photo

Convert binary to file


  • Please log in to reply
8 replies to this topic

#1 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 05 May 2012 - 06:23 PM

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





#2 Melba23

Melba23

    Yes, me!

  • Moderators
  • 15,305 posts

Posted 05 May 2012 - 07:19 PM

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
StringSize - Automatically size controls to fit text - ExtMsgBox - A user customisable replacement for MsgBox

Toast - Small GUIs which pop out of the Systray - Marquee - Scrolling tickertape GUIs

Scrollbars - Automatically sized scrollbars with a single command - GUIFrame - Subdivide GUIs into many adjustable frames

GUIExtender - Extend and retract multiple sections within a GUI - NoFocusLines - Remove the dotted focus lines from buttons, sliders, radios and checkboxes

ChooseFileFolder - Single and multiple selections from specified path tree structure - - Notify - Small notifications on the edge of the display

RecFileListToArray - An alternative to _FileListToArray with user-defined include/exclude masks, maximum recursion level, sorting and displayed path options

GUIListViewEx - Insert, delete, move, drag and sort ListView items


#3 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 06 May 2012 - 07:29 AM

@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, 06 May 2012 - 07:30 AM.


#4 PhoenixXL

PhoenixXL

    Be what you are, believe me its always the BEST...

  • Active Members
  • PipPipPipPipPipPip
  • 1,310 posts

Posted 06 May 2012 - 11:59 AM

Hey!! FSoft

Nice Meeting U
Maybe This is the UDF that will Do Your Work

Link: CLICK HERE

Thumbs Up if it Helped ;)


Regards
Phoenix XL
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.

#5 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 06 May 2012 - 01:51 PM

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, 06 May 2012 - 01:51 PM.


#6 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 06 May 2012 - 02:42 PM

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* Posted Image [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

#7 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 07 May 2012 - 08:55 AM

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

#8 ProgAndy

ProgAndy

    You need AutoItObject

  • MVPs
  • 2,508 posts

Posted 07 May 2012 - 09:24 AM

@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:
AutoIt         
$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)

  • Floppy likes this
*GERMAN* Posted Image [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

#9 Floppy

Floppy

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 302 posts

Posted 07 May 2012 - 11:38 AM

Thank you ProgAndy. Now it works!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users