Dear,
For an update we creates following example:
code:
$old_string="[old string]" ; - your old string value -
$new_string="<new string>" ; - your new string value -
;
$file="c:\your_file.txt" ; - your file -
$file_temp="%temp%\dummy.tmp"
$debug_mode="yes"
IF (Exist($file) = 1)
DEL $file_temp
IF (Open(1,$file,2) = 0) ; -read access-
IF (Open(2,$file_temp,5) = 0) ; -write access-
$line=ReadLine(1)
WHILE (@error = 0)
IF ($debug_mode = "yes")
? " -> "+$line
ENDIF
$i=Instr($line,$old_string)
IF ($i <> 0)
IF ($i = 1)
$nline=$new_string+Substr($line,Len($old_string)+1)
ELSE
IF ($i+Len($old_string)-1 = Len($line))
$nline=Substr($line,1,Instr($line,$old_string)-1)+$new_string
ELSE
$nline=Substr($line,1,Instr($line,$old_string)-1)+
$new_string+
Substr($line,Instr($line,$old_string)+Len($old_string))
ENDIF
ENDIF
ELSE
$nline=$line
ENDIF
IF ($debug_mode = "yes")
? " --> "+$nline
ENDIF
IF (WriteLine(2,$nline+CHR(13)+CHR(10)) <> 0)
ENDIF
$line=ReadLine(1)
LOOP
IF Close(2)
ENDIF
ENDIF
IF Close(1)
ENDIF
?
IF (Exist($file_temp) = 1)
COPY $file_temp $file /H
IF (@error <> 0)
? "Warning KIX: update "+Ucase($file)+" returns error @error (@serror)"
ELSE
DEL $file_temp
ENDIF
? "update "+Ucase($file)+" file."
ENDIF
ENDIF
? "update completed."
ELSE
? "already updated."
ENDIF
An example:
code:
[old string]123456789
123[old string]456789
123456789[old string]
becomes
code:
<new string>123456789
123<new string>456789
123456789<new string>
with screen output
code:
-> [old string]123456789
--> <new string>123456789
-> 123[old string]456789
--> 123<new string>456789
-> 123456789[old string]
--> 123456789<new string>
update c:\your_file.tx file.
update completed.
Greetings.
btw: we must take some precaution for a known flushing problem
with write-buffers. We are only use the WriteLine functions.
To prevent this kind of problems.
[ 27 May 2002, 18:23: Message edited by: MCA ]