Vous n'êtes pas connecté. Ce forum permet seulement les utilisateurs connectés pour poster. Si vous voulez faire un post sur le forum, s'il vous plaît connecter.
TeraTerm Macro 'filewriteln' overwrites next line (2020-01-21 20:09 by daminator #84185)
Hi folks!
I have an issue when I try to change something in a .txt-file. I'm about to create some kind of "default config" for my firmware flash script. The scripts checks for availiable value in the default-config-file, if some value is found, its used as a default value for the inputbox and if the value changes, the old value is replaced by the new one.
I have a few variables saved in the mentioned file, which look like this:
var1=10
var2=20
var3=30
var4=40
var5=50
...
After I write the value for var3 to 3000, the .txt-file looks like this:
var1=10
var2=20
var3=300
r4=40
var5=50
You can see, that the two new characters replace
I could read all the values an write them back into the file with the new values or i could write the new value on the end of the file. But is there any more elegant solution for this problem?
My code:
-------------------------------------------------------------------------
defaultFile = 'Default.ini'
defaultVariable = 'var3'
call checkForDefault
inputbox 'Value for var3:' 'Values' line
call checkForNewDefault
end
:checkForDefault
line = ''
fileopen fHandle defaultFile 0 1
filestrseek fHandle defaultVariable
if result > 0 then
filestrseek fHandle '='
filereadln fHandle line
endif
fileclose fHandle
return
:CheckForNewDefault
strcompare inputstr line
if result != 0 then
fileopen fHandle defaultFile 0
filestrseek fHandle defaultVariable
if result > 0 then
filestrseek fHandle '='
strconcat newinputstr inputstr
filewriteln fHandle newinputstr
endif
fileclose fHandle
endif
return
-------------------------------------------------------------------------