Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Adding text to file...

Posted on 2000-03-15
7
Medium Priority
?
224 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
  • 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 200 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 85

Expert Comment

by:ozo
ID: 2622200
perldoc -q append
0
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.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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 …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

876 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