Is there a way to overwrite a line

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
roni
Newbie
Posts: 1
Joined: Fri Oct 19, 2007 2:38 pm

Is there a way to overwrite a line

Post by roni » Fri Oct 19, 2007 3:00 pm

hi,

Is there a way to overwrite a line in text file



thanks

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Oct 19, 2007 3:05 pm

What you do is edit a copy of the file and overwrite the source.

You can do either:

1. Read the entire file into memory with ReadFile. Modify the required line. Then write the data out to a NEW file with WriteLn. Then delete the old file and rename the new one to the old name.

2. Read the lines in one by one with ReadLn. Output each line to a new file with WriteLn. When you get to the one you want to change, output the changes. At the end delete the old file and rename the new to old.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts