Archive: Writing to 2nd last line of file


Writing to 2nd last line of file
Hello,

I'm trying to append a string to the 2nd last line of a text file, but I'm not sure how I can do that. Would this be possible with the NSIS functions or is a plugin needed?

Thanks :D


See the NSIS documentation,
http://nsis.sourceforge.net/Docs/AppendixE.html#E.2

Name "My Application"
OutFile 'test.exe'
!define TEST_FILE "$EXEDIR\license.txt"

!include TextFunc.nsh

!insertmacro LineFind


Section
CopyFiles "${NSISDIR}\license.txt" "${TEST_FILE}"

${LineFind} "${TEST_FILE}" "" "-2" Example4
IfErrors 0 +2
MessageBox MB_OK "Error"
ExecShell open "${TEST_FILE}"
SectionEnd

Function Example4
FileWrite $R4 "---First Line---$\r$\n"
FileWrite $R4 "---Second Line ...---$\r$\n"

Push $0
FunctionEnd

Awesome, thanks a lot red wine!


You're welcome Backland, thanks goes to Instructor :)