Solved

Adding text to file...

Posted on 2000-03-15
7
218 Views
Last Modified: 2010-03-05
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??
0
Comment
Question by:cdc_sickle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
  • +1
7 Comments
 
LVL 8

Expert Comment

by:jhurst
ID: 2621899
There is no direct way to do it, sadly
0
 
LVL 8

Accepted Solution

by:
jhurst earned 50 total points
ID: 2621905
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
 
LVL 84

Expert Comment

by:ozo
ID: 2622200
perldoc -q append
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:craig_capel
ID: 2623269
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
 
LVL 2

Expert Comment

by:craig_capel
ID: 2623276
SOOOOOOOORRRRRRRRRYYYYYY, thought i was in the Delphi section still.....  i really am sorry
0
 

Author Comment

by:cdc_sickle
ID: 2623551
Jhurst, that is exactly how i panned on having to do it. Ill see if it works!
0
 

Author Comment

by:cdc_sickle
ID: 2623616
This worked, with a little touching up!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

623 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question