1 ; search & replace line in file.
\r
2 ;-------------------------
\r
3 ; parameter description
\r
4 ; $9 is filename to search
\r
5 ; $8 is string to search
\r
6 ; $7 is string to replace
\r
7 ;------------------------
\r
8 ; How to call function:
\r
9 ; Push "filename.txt"
\r
10 ; Push "the string to search"
\r
11 ; Push "the string to replace"
\r
12 ; Call un.ReplaceLine
\r
13 ;-----------------------
\r
14 Function un.ReplaceLine
\r
21 FileOpen $0 $9 "r" ; open target file for reading
\r
22 GetTempFileName $R0 ; get new temp file name
\r
23 FileOpen $1 $R0 "w" ; open temp file for writing
\r
25 FileRead $0 $2 ; read line from target file
\r
26 IfErrors done ; check if end of file reached
\r
27 StrCmp $2 "$8$\r$\n" 0 +2 ; compare line with search string with CR/LF
\r
28 StrCpy $2 "$7$\r$\n" ; change line
\r
29 StrCmp $2 "$8" 0 +2 ; compare line with search string without CR/LF (at the end of the file)
\r
30 StrCpy $2 "$7" ; change line
\r
31 FileWrite $1 $2 ; write changed or unchanged line to temp file
\r
35 FileClose $0 ; close target file
\r
36 FileClose $1 ; close temp file
\r
37 Delete $9 ; delete target file
\r
38 CopyFiles /SILENT $R0 $9 ; copy temp file to target file
\r
39 Delete $R0 ; delete temp file
\r
46 ; search & delete line in file.
\r
47 ;-------------------------
\r
48 ; parameter description
\r
49 ; $9 is filename to search
\r
50 ; $8 is string to search and delete
\r
52 ;------------------------
\r
53 ; How to call function:
\r
55 ; Push "filename.txt"
\r
56 ; Push "the string to search and delete"
\r
57 ; Call un.DeleteLine
\r
59 ;-----------------------
\r
60 Function un.DeleteLine
\r
66 FileOpen $0 $9 "r" ; open target file for reading
\r
67 GetTempFileName $R0 ; get new temp file name
\r
68 FileOpen $1 $R0 "w" ; open temp file for writing
\r
70 FileRead $0 $2 ; read line from target file
\r
71 IfErrors done ; check if end of file reached
\r
72 StrCmp $2 "$8$\r$\n" loop 0 ; if search string (with CR/LF) is found, goto loop
\r
73 StrCmp $2 "$8" loop 0 ; if search string is found at the end of the file, goto loop
\r
74 FileWrite $1 $2 ; write changed or unchanged line to temp file
\r
78 FileClose $0 ; close target file
\r
79 FileClose $1 ; close temp file
\r
80 Delete $9 ; delete target file
\r
81 CopyFiles /SILENT $R0 $9 ; copy temp file to target file
\r
82 Delete $R0 ; delete temp file
\r