Skip to content
⌘ NSIS Forum Archive

Writing to 2nd last line of file

4 posts

Backland#

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 😁
Red Wine#
See the NSIS documentation,

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