Floppy Posted May 5, 2012 Share Posted May 5, 2012 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted May 5, 2012 Moderators Share Posted May 5, 2012 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 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: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Floppy Posted May 6, 2012 Author Share Posted May 6, 2012 (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) ExitThe 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 May 6, 2012 by FSoft Link to comment Share on other sites More sharing options...
PhoenixXL Posted May 6, 2012 Share Posted May 6, 2012 Hey!! FSoft Nice Meeting U Maybe This is the UDF that will Do Your WorkLink: Thumbs Up if it Helped Regards Phoenix XL My code: 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. Link to comment Share on other sites More sharing options...
Floppy Posted May 6, 2012 Author Share Posted May 6, 2012 (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 May 6, 2012 by FSoft Link to comment Share on other sites More sharing options...
ProgAndy Posted May 6, 2012 Share Posted May 6, 2012 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 Link to comment Share on other sites More sharing options...
Floppy Posted May 7, 2012 Author Share Posted May 7, 2012 @ProgAndy: That doesn't work. I tried with a PDF and the new file created is corrupted. Link to comment Share on other sites More sharing options...
ProgAndy Posted May 7, 2012 Share Posted May 7, 2012 @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) Floppy 1 *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 Link to comment Share on other sites More sharing options...
Floppy Posted May 7, 2012 Author Share Posted May 7, 2012 Thank you ProgAndy. Now it works! 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