[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

No such file or directory

Nick Shaw

1/19/2008 7:42:00 PM

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.
--
Posted via http://www.ruby-....

4 Answers

forgottenwizard

1/19/2008 9:56:00 PM

0

On 04:42 Sun 20 Jan , 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")
> 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.
> --
> Posted via http://www.ruby-....
>
>

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.


Siep Korteling

1/19/2008 11:31:00 PM

0

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



--
Posted via http://www.ruby-....

Sebastian Hungerecker

1/20/2008 9:51:00 AM

0

Siep Korteling 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
--
Jabber: sepp2k@jabber.org
ICQ: 205544826

fedzor

1/20/2008 10:07:00 PM

0


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