[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

File.new raise an exception ?

Jean-François Boisvieux

3/26/2006 3:51:00 PM

Hello,

I'm pretty new to ruby and I've written some code to parse apache
logs, it works but now I want to store the result in a file. The
problem is as follow (using irb)

irb(main):001:0> foo = File.open("test")
Errno::ENOENT: No such file or directory - test
from (irb):1:in `initialize'
from (irb):1:in `open'
from (irb):1

I just do not understand the problem ( I can create a file with
python in the same directory ), what's wrong for me ?

thanks for a quick answer

Jean-François

2 Answers

Patrick Hof

3/26/2006 4:39:00 PM

0

Jean-François Boisvieux <jfb@mxs.fr> schrieb:

> irb(main):001:0> foo = File.open("test")
> Errno::ENOENT: No such file or directory - test
> from (irb):1:in `initialize'
> from (irb):1:in `open'
> from (irb):1
>
> I just do not understand the problem ( I can create a file with
> python in the same directory ), what's wrong for me ?

Ruby is opening the file for reading per default. As there seems to be
no file with the name test, you get the error. To open it for writing,
you have to say

File.open("test", "w")

Patrick

--
"Ah. Philosophy," said Om.
(Small Gods)

Jean-François Boisvieux

3/26/2006 4:58:00 PM

0

Thanks Patrick for this precise and clear answer

Jean-Francois

Le 26 mars 06 à 18:38, Patrick Hof a écrit :

> Jean-François Boisvieux <jfb@mxs.fr> schrieb:
>
>
>> irb(main):001:0> foo = File.open("test")
>> Errno::ENOENT: No such file or directory - test
>> from (irb):1:in `initialize'
>> from (irb):1:in `open'
>> from (irb):1
>>
>> I just do not understand the problem ( I can create a file with
>> python in the same directory ), what's wrong for me ?
>>
>
> Ruby is opening the file for reading per default. As there seems to be
> no file with the name test, you get the error. To open it for writing,
> you have to say
>
> File.open("test", "w")
>
> Patrick
>
> --
> "Ah. Philosophy," said Om.
> (Small Gods)
>