# File.open and File.new problem for a newbie

**URL:** <https://www.ruby-forum.com/t/file-open-and-file-new-problem-for-a-newbie/87328>\
**Category:** Ruby\
**Created:** [March 26, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/file-open-and-file-new-problem-for-a-newbie/87328 "2006-03-26T18:14:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jean-Francois\_Boisv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@Jean-Francois\_Boisv](https://www.ruby-forum.com/u/Jean-Francois_Boisv)\
**Post date:** [March 26, 2006, 6:14pm UTC](https://www.ruby-forum.com/t/file-open-and-file-new-problem-for-a-newbie/87328/1 "2006-03-26T18:14:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Jean-Francois\_Boisv](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/2bfe46/32.png) [@Jean-Francois\_Boisv](https://www.ruby-forum.com/u/Jean-Francois_Boisv)\
**Post date:** [March 26, 2006, 6:23pm UTC](https://www.ruby-forum.com/t/file-open-and-file-new-problem-for-a-newbie/87328/2 "2006-03-26T18:23:18Z")

</div>

On Mar 26, 2006, at 6:13 PM, Jean-Francois Boisvieux wrote:

> 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
