ennis Posted March 15, 2005 Posted March 15, 2005 (edited) Im trying to merge some text files into a new empty text file..some are a few megs others smaller. My code doesnt seem to work. It only adds carriage returns into the new file. I've tried the _fileappend function as well..it does the same thing mine does. here it is (btw the array contents or size really doesnt matter as long as it has an entry for each file which it does): Local $regHandle = fileopen("C:\reg.txt", 1) for $count = 0 to ubound($regArray) - 1 if fileexists('C:\temp\reg' & $count & '.tmp') then Local $tmpregHandle = fileopen('C:\temp\reg' & $count & '.tmp', 0) Local $regString while 1 $regString = filereadLine($tmpregHandle) if @ERROR = -1 then EXITLOOP filewriteLine($regHandle, $regString) WEND fileclose($tmpregHandle) else msgbox(4096, "Error", "File " & $count & " does not exist!") endif Next fileclose($regHandle) and ive also tried this Local $regHandle = fileopen("C:\reg.txt", 1) for $count = 0 to ubound($regArray) - 1 if fileexists('C:\temp\reg' & $count & '.tmp') then Local $tmpregHandle = fileopen('C:\temp\reg' & $count & '.tmp', 0) Local $regString = fileread($tmpregHandle, filegetsize('C:\temp\reg' & $count & '.tmp')) filewrite($regHandle, $regString) fileclose($tmpregHandle) else msgbox(4096, "Error", "File " & $count & " does not exist!") endif Next fileclose($regHandle) not sure why it wont work..my best guess is maybe its too big of a string but the line by line version should have fixed that. Well thnx if u figure it out. Ennis Edited March 15, 2005 by ennis
automagician Posted March 16, 2005 Posted March 16, 2005 (edited) Try something along these lines: #include <file.au3> Local $regHandle = fileopen("C:\reg.txt", 1) for $count = 0 to ubound($regArray) - 1 if fileexists('C:\temp\reg' & $count & '.tmp') then $file = 'C:\temp\reg' & $count & '.tmp' Local $tmpregHandle = fileopen($file, 0) Local $regString $tot_lines = _FileCountLines($file) $i = 1 While $i <= $tot_lines $regString = filereadLine($tmpregHandle, $i) if @ERROR = -1 then EXITLOOP filewriteLine($regHandle, $regString) $i = $i + 1 WEnd fileclose($tmpregHandle) else msgbox(4096, "Error", "File " & $count & " does not exist!") endif Next fileclose($regHandle) I didn't test the code, but it should work....When you are doing the FileReadLine, you need to specify what line. ***_FileCountLines needs file location, not handle, sorry...I just updated the snipit above. Edited March 16, 2005 by automagician
zcoacoaz Posted March 16, 2005 Posted March 16, 2005 you don't nned to specify the line but it helps in some cases [font="Times"] If anyone remembers me, I am back. Maybe to stay, maybe not.----------------------------------------------------------------------------------------------------------[/font][font="Times"]Things I am proud of: Pong! in AutoIt | SearchbarMy website: F.R.I.E.S.A little website that is trying to get started: http://thepiratelounge.net/ (not mine)[/font][font="Times"] ----------------------------------------------------------------------------------------------------------[/font][font="Arial"]The newbies need to stop stealing avatars!!! It is confusing!![/font]
automagician Posted March 16, 2005 Posted March 16, 2005 Sorry about that, I used the the line number and it worked for me, I didn't mean to say *need*
phillip123adams Posted March 16, 2005 Posted March 16, 2005 Im trying to merge some text files into a new empty text file..some are a few megs others smaller.<{POST_SNAPBACK}>How about the COPY command. It allows contatenation of multiple files into a new file.Example: COPY "file1"+"file2"+"file3" "file4"Run(@comspec & ' /c COPY "' & $File1 & '"+"' & $File2 & '" "' & $File3 & '"') Phillip
ennis Posted March 16, 2005 Author Posted March 16, 2005 (edited) How about the COPY command. It allows contatenation of multiple files into a new file.Example: COPY "file1"+"file2"+"file3" "file4"Run(@comspec & ' /c COPY "' & $File1 & '"+"' & $File2 & '" "' & $File3 & '"')<{POST_SNAPBACK}>Thnx bud..the copy command did it..One weird thing is sometimes it adds a weird square character at the end -> -.maybe its a dos carriage return.not sure..but it doesnt on larger files...I appreciate the helpEnnis Edited March 16, 2005 by ennis
Blue_Drache Posted March 16, 2005 Posted March 16, 2005 (edited) Thnx bud..the copy command did it..One weird thing is sometimes it adds a weird square character at the end -> -.maybe its a dos carriage return.not sure..but it doesnt on larger files...I appreciate the helpEnnis<{POST_SNAPBACK}>That's acutally the EOF marker. I sometimes see it as a left arrow <- (all one character though). Dependant on the font.... I use TERMINAL font for notepad. Lets me see all the old skewel DOS ASCII characters.... Edited March 16, 2005 by Blue_Drache Lofting the cyberwinds on teknoleather wings, I am...The Blue Drache
phillip123adams Posted March 16, 2005 Posted March 16, 2005 Thnx bud..the copy command did it..One weird thing is sometimes it adds a weird square character at the end -> -.maybe its a dos carriage return.not sure..but it doesnt on larger files...I appreciate the helpEnnis<{POST_SNAPBACK}>You're welcome. Like Larry says, include the /b switch and that should solve that problem. Phillip
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