Overwrite file line number in text file: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
m (Wikipedia python library)
 
m (Adding new author and category links.)
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{PageAuthor|Afrow UK}}
== Description ==
== Description ==
This function overwrites an existing line in a text file with a specified string.
This function overwrites an existing line in a text file with a specified string.
Line 59: Line 61:
-Stu
-Stu


Page author: Afrow UK
[[Category:Text Files Manipulation Functions]]

Latest revision as of 13:33, 24 June 2005

Author: Afrow UK (talk, contrib)


Description

This function overwrites an existing line in a text file with a specified string.

Usage

Push hello
Push 24
Push "$INSTDIR\file.txt"
Call WriteToFileLine2

The Function

Function WriteToFileLine2
Exch $0 ;file
Exch
Exch $1 ;line number
Exch 2
Exch $2 ;string to write
Exch 2
Push $3
Push $4
Push $5
Push $6
Push $7
 
 GetTempFileName $7
 FileOpen $4 $0 r
 FileOpen $5 $7 w
 StrCpy $3 0
 
Loop:
ClearErrors
FileRead $4 $6
IfErrors Exit
 IntOp $3 $3 + 1
 StrCmp $3 $1 0 +3
FileWrite $5 "$2$\r$\n"
Goto Loop
FileWrite $5 $6
Goto Loop
Exit:
 
 FileClose $5
 FileClose $4
 
SetDetailsPrint none
Delete $0
Rename $7 $0
SetDetailsPrint both
 
Pop $7
Pop $6
Pop $5
Pop $4
Pop $3
Pop $2
Pop $1
Pop $0
FunctionEnd

-Stu