No such file or directory

N

Nick Shaw

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.
 
F

forgottenwizard

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.

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.
 
S

Siep Korteling

Nick said:
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
 
S

Sebastian Hungerecker

Siep said:
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
 
F

fedzor

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
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top