Adding text to file...

I know how to add text to an existing fine, except it adds it to the end. How do I add it to the beginning of the file??
cdc_sickleAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
jhurstConnect With a Mentor Commented:
The problem is that the underlying operating system file system does not usually have an 'open and insert at start'.  Where as, as you know there is the >> to add to the end.

So, what you will need to do is read the old data and insert the new then re-write the whole thing out.

Something like:
open(FIL,"<theFile");
@=<FIL>; gets what was there
close(FIL);
open(FIL,">theFile");
print "your new data\n";
print @x;
close(FIL);

I realize that this is not what you want.  Sadly, it is all you can have.
0
 
jhurstCommented:
There is no direct way to do it, sadly
0
 
ozoCommented:
perldoc -q append
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
craig_capelCommented:
another way....

Crude, but hey it works!!!

Stick an invisble memo onto your form, so the user can not see whats happening.... and do this..

memo1.lines.loadfromfile('c:\autoexec.bat');
memo1.lines.insert(0,'rem Hello');
memo1.lines.insert(1,'rem craig');
memo1.lines.insert(2,'rem was');
memo1.lines.insert(3,'rem here');
memo1.lines.savetofile('c:\autoexec.bat');


Stick it somewhere.... And thats the easiest way of doing it!....

Craig C. Jhurst, un Comment it as an Answer!

0
 
craig_capelCommented:
SOOOOOOOORRRRRRRRRYYYYYY, thought i was in the Delphi section still.....  i really am sorry
0
 
cdc_sickleAuthor Commented:
Jhurst, that is exactly how i panned on having to do it. Ill see if it works!
0
 
cdc_sickleAuthor Commented:
This worked, with a little touching up!
0
All Courses

From novice to tech pro — start learning today.