File.new raise an exception ?

  • Thread starter Jean-François Boisvieux
  • Start date
J

Jean-François Boisvieux

Hello,

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

irb(main):001:0> foo =3D 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 =20
python in the same directory ), what's wrong for me ?

thanks for a quick answer

Jean-Fran=E7ois=20=
 
P

Patrick Hof

--m51xatjYGsM+13rf
Content-Type: text/plain; charset=iso-8859-1
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Jean-Fran=E7ois Boisvieux said:
irb(main):001:0> foo =3D File.open("test")
Errno::ENOENT: No such file or directory - test
from (irb):1:in `initialize'
from (irb):1:in `open'
from (irb):1
=20
I just do not understand the problem ( I can create a file with =20
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

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

--m51xatjYGsM+13rf
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)

iD8DBQFEJsPvfpK5yKGUrIURApKQAJ4q0X94wPuAnKKZblHHrpBQO7SvjQCghOSt
W9/zK8BqHCFldSrw7krOx74=
=SLPb
-----END PGP SIGNATURE-----

--m51xatjYGsM+13rf--
 
J

Jean-François Boisvieux

Thanks Patrick for this precise and clear answer

Jean-Francois

Le 26 mars 06 =E0 18:38, Patrick Hof a =E9crit :
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top