File.open and File.new problem for a newbie

  • Thread starter Jean-Francois Boisvieux
  • Start date
J

Jean-Francois Boisvieux

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
 
D

Daniel Harple

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 ?

You must open the file for writing:

open("test", "w") do |file|
# ...
end # -> File is automatically closed here, even if an exception is
thrown.

-- Daniel
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top