Replacing Lines in a Text File: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library) |
m (Updated author and download links, and changed format of some pages.) |
||
Line 25: | Line 25: | ||
Delete $R0</highlight-nsis> | Delete $R0</highlight-nsis> | ||
Page author: KiCHiK | Page author: [[User:KiCHiK|KiCHiK]] |
Revision as of 12:16, 23 April 2005
Description
This script will replace every occurrence of the line "line to replace" with the line "replacement of line" in the file called "file.txt".
The Script
ClearErrors FileOpen $0 "file.txt" "r" GetTempFileName $R0 FileOpen $1 $R0 "w" loop: FileRead $0 $2 IfErrors done StrCmp $2 "line to replace$\r$\n" 0 +3 FileWrite $1 "replacement of line$\r$\n" Goto loop StrCmp $2 "line to replace" 0 +3 FileWrite $1 "replacement of line" Goto loop FileWrite $1 $2 Goto loop done: FileClose $0 FileClose $1 Delete "file.txt" CopyFiles /SILENT $R0 "file.txt" Delete $R0
Page author: KiCHiK