iterating over directories

D

Dafydd Fontenot

I got this oneliner that isn't producing the output I was expecting (it
printing all of the directories in the linux root directory).

irb(main):012:0> Dir.new("/").each { |name| puts name if
File.directory?(name) }
..
 
A

Andrew Timberlake

I got this oneliner that isn't producing the output I was expecting (it
printing all of the directories in the linux root directory).

irb(main):012:0> Dir.new("/").each { |name| puts name if
File.directory?(name) }
..
.
=> #<Dir:/>

Does anyone know what I might be doing incorrectly?

It should be printing all of the directories in the linux root.
What do you want it to do?

Andrew Timberlake
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake

"I have never let my schooling interfere with my education" - Mark Twain
 
D

Dafydd Fontenot

Andrew said:
On Wed, Apr 15, 2009 at 7:41 AM, Dafydd Fontenot

It should be printing all of the directories in the linux root.
What do you want it to do?

I'm just having it print for now for debugging purposes. But eventually
it will be storing all of the directory names in an array. Or is there
any other way I can control that block to do different things if the
current item is a file and do something else if it is a directory?
 
S

Siddick Ebramsha

Solution :-
Dir.new("/").each { |name| puts name if File.directory?( "/" + name) }
 

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

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top