Archive: Loop Help


Loop Help
I have some code that find a specific line in a file and and adds in several other lines directly after it. The loop works great (someone on this forum helped me with it) but I'm wondering how I might add add some more code into the loop to add several other lines to a *different* section of the file.

The code and problem is outlined here:

http://www.offtopicproductions.com/temp/nsishelp.txt

Thanks:-)


After reading up on FileRead I've modified the code a bit and I think it's almost how I want it. The problem seems to be (I think) that when it gets to the second loop it's already at the bottom of the file and so reads nothing and sets the error flag. I think I just need a way to return it to the top of the file before the second loop.

http://www.offtopicproductions.com/temp/nsishelp2.txt


"adds in several other lines directly after it"


FileOpen $4 "$INSTDIR\TNM\System\TNM.ini" "r"
GetTempFileName $R1
FileOpen $5 $R1 "w"

loop:
FileRead $4 $6
IfErrors done

FileWrite $5 $6
StrCmp $6 "CacheExt=.uxx$\r$\n" 0 +3
FileWrite $5 "...$\r$\n"
FileWrite $5 "...$\r$\n"

StrCmp $6 "EditPackages=IpServer$\r$\n" 0 loop
FileWrite $5 "...$\r$\n"
FileWrite $5 "...$\r$\n"
Goto loop

done:
FileClose $4
FileClose $5

Awesome! Thanks a lot:D

Now I better decipher exactly what everything does so I can do it myself next time:-)


You are welcome.