BlueScreen Posted December 21, 2005 Posted December 21, 2005 Hi All, I am trying to read a simple text file (small.txt) (attached) to an array and put all it's content in another text file (output.txt). File are not identical (I have compared them). Looks like that in the output.txt file, there is always an extra line? Why? Can it be do without this extra line??? Thanks, #include <file.au3> Dim $aRecords If Not _FileReadToArray("c:\small.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array! error:" & @error) Exit EndIf $x=Fileopen ("c:\output.txt",2) For $i=1 to 3 If $i<>3 Then Filewriteline ($x,$arecords[$i] & @LF) Else Filewriteline ($x,$arecords[$i] & @CR) EndIf Nextsmall.txt
Valuater Posted December 21, 2005 Posted December 21, 2005 (edited) follow the process that help gives you #include <file.au3> Dim $aRecords If Not _FileReadToArray("error.log",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf For $x = 1 to $aRecords[0] Msgbox(0,'Record:' & $x, $aRecords[$x]) Next thus #include <file.au3> Dim $aRecords If Not _FileReadToArray("error.log",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $i=Fileopen ("c:\output.txt",2) For $x = 1 to $aRecords[0] -1 Msgbox(0,'Record:' & $x, $aRecords[$x]) Filewriteline ($i,$arecords[$x] & @CR) Next Filewriteline ($i,$arecords[$x] ) oh yea and file close 8) Edited December 21, 2005 by Valuater
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 Thanks, Valuater... I have run your posted script, files small.txt and output.txt are not identical. Try it...
Valuater Posted December 21, 2005 Posted December 21, 2005 #include <file.au3> Dim $aRecords If Not _FileReadToArray("error.log",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $i=Fileopen ("c:\output.txt",2) For $x = 1 to $aRecords[0] -1 Msgbox(0,'Record:' & $x, $aRecords[$x]) Filewriteline ($i,$arecords[$x] & @CRLF) Next Filewriteline ($i,$arecords[$x] ) this does it 8)
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 Sorry, Valuater... I have compared the files using Total commander. Files are NOT identical...
Valuater Posted December 21, 2005 Posted December 21, 2005 (edited) ok... this does the trick $File_1 = "c:\small.txt" $File_2 = "c:\output.txt" $file_info = FileRead($File_1, FileGetSize($File_1)) FileWrite($File_2, $file_info) 8) Edited December 21, 2005 by Valuater
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 The file "small.txt" is in c:\ This is (your) script I'm running( changed the line you mentioned) #include <file.au3> Dim $aRecords If Not _FileReadToArray("c:\small.txt",$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $i=Fileopen ("c:\output.txt",2) For $x = 1 to $aRecords[0] -1 Msgbox(0,'Record:' & $x, $aRecords[$x]) Filewriteline ($i,$arecords[$x] & @CRLF) Next Filewriteline ($i,$arecords[$x] ) Attached is a screenshot confirming that they are not identical and that there is an extra empty line at the end of output.txt. Looks like it was created when file was opened?
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 Thanks, man. It does the trick... The issue is that I have a BIG text file to read and must use FileWriteLine to write in the output file, since I will not want to write the entire file (only sections of it depending of a condition) I will like to use the FileReadToArray... Possible?
Valuater Posted December 21, 2005 Posted December 21, 2005 yes... lete me take another look at what i can do 8)
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 Thanks!!!!! I will also post my entire script soon...
Valuater Posted December 21, 2005 Posted December 21, 2005 this will do it.. $File_1 = "c:\small.txt" $File_2 = "c:\output.txt" #include <file.au3> Dim $aRecords If Not _FileReadToArray($File_1,$aRecords) Then MsgBox(4096,"Error", " Error reading log to Array error:" & @error) Exit EndIf $i=Fileopen ($File_2,2) For $x = 1 to $aRecords[0] -1 Filewriteline ($i,$arecords[$x] & @CRLF) Next Filewrite ($i, ($arecords[$x])) 8)
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 Thanks Valuater... This is close enough On the posted script, if you open Notepad, files seems indentical, however, if you compare them using total commander, you will observe that there is an empty line (god knows from where it came) between each written line... I have overcome it by changing from Filewriteline ($i,$arecords[$x] & @CRLF) to Filewriteline ($i,$arecords[$x] & @LF) Thanks, dude
BlueScreen Posted December 21, 2005 Author Posted December 21, 2005 Although it works, it strange since in the HELP file it is written: "If the line does NOT end in @CR or @LF then a DOS linefeed (@CRLF) will be automatically added.", so why in the last line of code posted there is no empty line as it should be (since there is no @CR ot @LF in the code line) Hmmmm....
Valuater Posted December 21, 2005 Posted December 21, 2005 Although it works, it strange since in the HELP file it is written: "If the line does NOT end in @CR or @LF then a DOS linefeed (@CRLF) will be automatically added.", so why in the last line of code posted there is no empty line as it should be (since there is no @CR ot @LF in the code line)Hmmmm....you quotedFileWriteLinesee FileWrite( no @CR included)8)
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