Replacing Lines in a Text File: Difference between revisions
From NSIS Wiki
Jump to navigationJump to search
m (Updated author and download links, and changed format of some pages.) |
m (Updated author links.) |
||
Line 1: | Line 1: | ||
{|align=right | |||
|<small>Author: [[{{ns:2}}:KiCHiK|KiCHiK]] ([[{{ns:3}}:KiCHiK|talk]], [[{{ns:-1}}:Contributions/KiCHiK|contrib]])</small> | |||
|} | |||
<br style="clear:both;"> | |||
== Description == | == 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". | This script will replace every occurrence of the line "line to replace" with the line "replacement of line" in the file called "file.txt". | ||
Line 24: | Line 28: | ||
CopyFiles /SILENT $R0 "file.txt" | CopyFiles /SILENT $R0 "file.txt" | ||
Delete $R0</highlight-nsis> | Delete $R0</highlight-nsis> | ||
Revision as of 03:02, 30 April 2005
Author: KiCHiK (talk, contrib) |
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