[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Re: Writing a file, without deleting it's current content

james_b

4/2/2006 10:14:00 PM

Jeppe Jakobsen wrote:
> Hi, I just read about the ".write" method.
> Let's say that I've just written a string to a file, "file.txt". Then I want
> to add some more information to it, on the next line. I use .write again and
> my info got replaced. How do I add to the without deleting what's already in
> it. I know I can load the string from it and then add them together, but
> isn't there a smarter way to do it, like writing to the next line?
>
> Thanks in advance :)
>

Look up the "append" option for File when opening for writing.


--
James Britt

"Programs must be written for people to read, and only incidentally
for machines to execute."
- H. Abelson and G. Sussman
(in "The Structure and Interpretation of Computer Programs)


2 Answers

Jeppe Jakobsen

4/3/2006 11:22:00 AM

0

ok just to make sure I got it right:

File.open("myFile.txt.", APPEND="This is the string I'm writing" )

Correct?

2006/4/3, James Britt <james_b@neurogami.com>:
>
> Jeppe Jakobsen wrote:
> > Hi, I just read about the ".write" method.
> > Let's say that I've just written a string to a file, "file.txt". Then I
> want
> > to add some more information to it, on the next line. I use .write again
> and
> > my info got replaced. How do I add to the without deleting what's
> already in
> > it. I know I can load the string from it and then add them together, but
> > isn't there a smarter way to do it, like writing to the next line?
> >
> > Thanks in advance :)
> >
>
> Look up the "append" option for File when opening for writing.
>
>
> --
> James Britt
>
> "Programs must be written for people to read, and only incidentally
> for machines to execute."
> - H. Abelson and G. Sussman
> (in "The Structure and Interpretation of Computer Programs)
>
>


--
"winners never quit, quitters never win"

Daniel Baird

4/3/2006 11:27:00 AM

0

erm, try this:

myfile = File.open("myFile.txt","a")
myfile << "This is the string I'm writing"


On 03/04/06, Jeppe Jakobsen <jeppe88@gmail.com> wrote:
>
> ok just to make sure I got it right:
>
> File.open("myFile.txt.", APPEND="This is the string I'm writing" )
>
> Correct?
>
> 2006/4/3, James Britt <james_b@neurogami.com>:
> >
> > Jeppe Jakobsen wrote:
> > > Hi, I just read about the ".write" method.
> > > Let's say that I've just written a string to a file, "file.txt". Then
> I
> > want
> > > to add some more information to it, on the next line. I use .write
> again
> > and
> > > my info got replaced. How do I add to the without deleting what's
> > already in
> > > it. I know I can load the string from it and then add them together,
> but
> > > isn't there a smarter way to do it, like writing to the next line?
> > >
> > > Thanks in advance :)
> > >
> >
> > Look up the "append" option for File when opening for writing.
> >
> >
> > --
> > James Britt
> >
> > "Programs must be written for people to read, and only incidentally
> > for machines to execute."
> > - H. Abelson and G. Sussman
> > (in "The Structure and Interpretation of Computer Programs)
> >
> >
>
>
> --
> "winners never quit, quitters never win"
>
>


--
Daniel Baird
http://danie... (TiddlyW;nks! :: Whiteboard Koala :: Blog :: Things
That Suck)
[[My webhost uptime is ~ 92%.. if no answer pls call again later!]]