Solved

Adding text to file...

Posted on 2000-03-15
7
177 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 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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

747 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now