Reading contents of all files from a Directory

J

Jesús Gabriel y Galán

Many Thanks Robert, I did the following,

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

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.

Try:

file.foreachline {|line| print line}

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

Jesus.
 
R

Robert Klemme

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
 
H

Hawksury Gear

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!
 

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
474,159
Messages
2,570,879
Members
47,413
Latest member
ReeceDorri

Latest Threads

Top