Sign in to follow this  
Followers 0
laphlaw

Add a line of text to a specified line

2 posts in this topic

How would I write a line to the beginning of a file, instead of appending it to the end? I've searched the forums, but haven't found a solution.

For that matter, is there a way to insert a line of text to a specified line within that file?

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

In psuedo code:

$abc = open original file for read-only
$xyz = open new file in write mode

$counter=0
$YourLineNum="25"; Whatever line you want
$YourLineText="I want to insert this line"
start loop
   $counter = $counter + 1
   if end of file then exit loop
   $line = Read line from $abc
   if $counter = $YourLineNum then
      write $YourLineText into $xyz
      write $line into $xzy
   else
      write $line into $xyz
   endif
end loop

Close $abc
Close $xyz

Check out the help file for FileOpen() Fileclose() FileReadLine() FileWriteLine() and While

Edited by SpookMeister

[u]Helpful tips:[/u]If you want better answers to your questions, take the time to reproduce your issue in a small "stand alone" example script whenever possible. Also, make sure you tell us 1) what you tried, 2) what you expected to happen, and 3) what happened instead.[u]Useful links:[/u]BrettF's update to LxP's "How to AutoIt" pdfValuater's Autoit 1-2-3 Download page for the latest versions of Autoit and SciTE[quote]<glyph> For example - if you came in here asking "how do I use a jackhammer" we might ask "why do you need to use a jackhammer"<glyph> If the answer to the latter question is "to knock my grandmother's head off to let out the evil spirits that gave her cancer", then maybe the problem is actually unrelated to jackhammers[/quote]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0