Notifications
Clear all
[Closed] How add text in specified position to already existing file
Oct 21, 2014 9:42 am
I try to add text to a specified position to already existing file. When i run my code new text added at the end file and not in the specified position. what did i do wrong?
fs=openFile "c:/my.txt" mode:"a+"
skipToString fs ";"
seek fs (filepos -1)
format "add new text" to:fs
close fs
му.txt content
levl_name # tech_lvl,military_lvl,desert_lvl;
body # Column,Pilaster,Plinth,Wall_,Floor_;
prefix1 # _left_,_right_,_top_,_bottom_;
prefix2 # _bad_, _good_,_Tall_, _Low_;
2 Replies
1 Reply
fs = openFile "c:/my.txt" [b]mode:"r+" [/b]
[b]seek fs 0 [/b]
skipToString fs ";"
format "add new text" to:fs
close fs
to make it works right you have to:
#1 open file in “r+” mode
#2 set position correctly (probably at top) before skipping to a string
Oct 21, 2014 9:42 am
There’s nothing wrong as the “a” mode will always write at the end of the file no matter the filepos.
You may want to try to delete everything between filepos and the end of the file, append your text and append what you deleted.