Archive: A script...


A script...
I'm going to write a script to combine two files together into one.
I just need to know the proper way to get to the end of the 1st txt file, so that I can begin writing text from the 2nd txt file onto the end.

This is how far I could get, but I've no idea what to do next...


FileOpen $0 $INSTDIR\temp1.txt w
FileSeek $0 0 END $1
FileOpen $2 $INSTDIR\temp2.txt r
FileRead $2 $3

Just keep writing into $0 in a loop until you can't read from $2 no more. NSIS doesn't process the input so there shouldn't be any problems with the line breaks.


So you mean, when it gets to the end of file 1, that means it's at the end and I can then write to it.

Okey!

-Stu


But you need to open it with append mode (a) and not write (w) because write will first delete everything in the file.


I'll test it now.
I think I have got some things completely wrong - I am assuming that FileWrite will always write to the start of the file.


Function JoinFiles
Exch $1
Exch
Exch $3
Push $0
Push $2
FileOpen $0 $1 a
FileOpen $2 $3 r
loop1:
FileRead $0 $1
IfErrors doneloop1
Goto loop1
doneloop1:
FileWrite $0 "$\n$\r$\n$\rEcho.$\n$\r$\n$\rEcho \
==============================================\
$\n$\r$\n$\rEcho.$\n$\r$\n$\r" # Optional divider
loop2:
FileRead $2 $1
FileWrite $0 $1
IfErrors done
Goto loop2
done:
Pop $2
Pop $0
Pop $3
Pop $1
FunctionEnd


Edit: This seems to work fine.

-Stu

FileWrite will write to where the file pointer is. The file pointer starts at the begining of the file in all modes (a,r,w). To write to the end of the file you still need to seek (change the file pointer) as you've done in the first script.


Final script:
http://nsis.sourceforge.net/archive/...instances=0,11

Works nicely :)

-Stu