substitute stings in files
I want to make nsis open a file, look for a string, and substitute that for another one of different lenth. I am trying to work with those file commands but I can't make them do what I want, could anyone help me? thanks🙂
16 posts
StrCmp $2 "line to replace$\r$\n" 0 +2
FileWrite $1 "replacement of line$\r$\n"
Goto loop use StrReplace and place the result in the new file.Section "-Change File"
!define ENCINI "$INSTDIR\file2change.txt"
FileOpen $0 "${ENCINI}" r
GetTempFileName $R0
FileOpen $1 $R0 w
loop:
FileRead $0 $2
IfErrors done
StrCmp $2 "first line to replace$\r$\n" igual dife
igual:
FileWrite $1 "replacement of first line$\r$\n"
Goto loop
dife:
StrCmp $2 "second line to replace$\r$\n" igual2 dife2
igual2:
FileWrite $1 "replacement of second line$\r$\n"
Goto loop
dife2:
FileWrite $1 $2
Goto loop
done:
FileClose $0
FileClose $1
Delete "${ENCINI}"
CopyFiles /SILENT $R0 "${ENCINI}"
SectionEnd