Reading contents of all files from a Directory

Try:

file.foreachline {|line| print line}

It seems Pathname objects don't have an each method...

Jesus.

···

On Sun, Apr 4, 2010 at 7:58 PM, Hawksury Gear <blackhawk_932@hotmail.com> wrote:

Even better

require 'pathname'
dir = Pathname "K:/test"

dir.each_entry do |file|
if file.file?
file.each_line do |line|
...
end
end
end

Cheers
robert

Many Thanks Robert, I did the following,

require 'pathname'
dir= Pathname "K:/test"
dir.each_entry do |file|
if file.file?
file.each {|line| print line} ## Checking if it can access a line in a
file
end
end

It isn't giving any error message which is great but also not Displaying
any Output.
Probably i am not using file.each{|line| print line} correctly.

Even better

require 'pathname'
dir = Pathname "K:/test"

dir.each_entry do |file|
   if file.file?
     file.each_line do |line|
       ...
     end
   end
end

Cheers
  robert

Many Thanks Robert, I did the following,

require 'pathname'
dir= Pathname "K:/test"
dir.each_entry do |file|
  if file.file?
file.each {|line| print line} ## Checking if it can access a line in a file
  end
end

It isn't giving any error message which is great but also not Displaying any Output.

Are you sure?

irb(main):004:0> pn.each {|l| p l}
NoMethodError: undefined method `each' for #<Pathname:clnt.rb>
         from (irb):4
         from /usr/local/bin/irb19:12:in `<main>'

Probably i am not using file.each{|line| print line} correctly.

I suggest you read my posting again and / or consult documentation.

Regards

  robert

···

On 04.04.2010 19:58, Hawksury Gear wrote:

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/

Probably i am not using file.each{|line| print line} correctly.

I suggest you read my posting again and / or consult documentation.

Regards

  robert

All works , Thanks very much!

···

--
Posted via http://www.ruby-forum.com/\.