# No such file or directory

**URL:** <https://www.ruby-forum.com/t/no-such-file-or-directory/126580>\
**Category:** Ruby\
**Created:** [January 19, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/no-such-file-or-directory/126580 "2008-01-19T20:42:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [January 19, 2008, 8:42pm UTC](https://www.ruby-forum.com/t/no-such-file-or-directory/126580/1 "2008-01-19T20:42:08Z")

</div>

Hi, Ive just started learning Ruby and I’m having a problem with the  
following program. I’m running it on Ubuntu.

lines = File.readlines("/home/nick/ruby/analyzer/oliver.txt")  
line\_count = lines.size  
text = lines.join

puts “#{line\_count} lines”

total\_characters = text.length  
puts “#{total\_characters} characters”

I keep getting a “No such file or directory error” and I can’t  
understand why. The file definitely exists at that location. It’s really  
annoying me.

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [January 19, 2008, 10:58pm UTC](https://www.ruby-forum.com/t/no-such-file-or-directory/126580/2 "2008-01-19T22:58:24Z")

</div>

On 04:42 Sun 20 Jan , Nick Shaw wrote:

> puts “#{total\_characters} characters”
> 
> ## I keep getting a “No such file or directory error” and I can’t understand why. The file definitely exists at that location. It’s really annoying me.
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

Make sure there isn’t a typo, and make sure you have access to the file.  
Its obviously not being seen by Ruby, so unless there is some other odd  
problem, I have no clue what it would be.

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [January 20, 2008, 12:30am UTC](https://www.ruby-forum.com/t/no-such-file-or-directory/126580/3 "2008-01-20T00:30:55Z")

</div>

Nick Shaw wrote:

> Hi, Ive just started learning Ruby and I’m having a problem with the  
> following program. I’m running it on Ubuntu.
> 
> lines = File.readlines("/home/nick/ruby/analyzer/oliver.txt")

(…)  
f = “/home/nick/ruby/analyzer/oliver.txt”  
lines = File.new(f).readlines  
#the rest of your code is fine.

The “f” thing is there because of this forum’s line-width.

Regards,

Siep

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [January 20, 2008, 11:08pm UTC](https://www.ruby-forum.com/t/no-such-file-or-directory/126580/4 "2008-01-20T23:08:06Z")

</div>

On Jan 19, 2008, at 2:42 PM, Nick Shaw wrote:

> I keep getting a “No such file or directory error” and I can’t  
> understand why. The file definitely exists at that location. It’s  
> really  
> annoying me.

I think this sounds like a shell directory. Are you in the proper  
directory when you run it?

if the file’s on your desktop…  
% cd Desktop  
% ruby file

---

<div class="post-metadata">

**Author:** ![nicksnels](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/aca169/32.png) [@nicksnels](https://www.ruby-forum.com/u/nicksnels)\
**Post date:** [January 20, 2008, 10:51am UTC](https://www.ruby-forum.com/t/no-such-file-or-directory/126580/5 "2008-01-20T10:51:08Z")

</div>

Siep K. wrote:

> > lines = File.readlines("/home/nick/ruby/analyzer/oliver.txt")
> 
> f = “/home/nick/ruby/analyzer/oliver.txt”  
> lines = File.new(f).readlines  
> #the rest of your code is fine.

The original version is actually better. Yours will keep the file open  
until  
the script finishes.

HTH,  
Sebastian
