[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

iterating over directories

Dafydd Fontenot

4/15/2009 5:42:00 AM

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) }
.
5 Answers

Andrew Timberlake

4/15/2009 5:59:00 AM

0

On Wed, Apr 15, 2009 at 7:41 AM, Dafydd Fontenot
<fontenot.1031@gmail.com> wrote:
> 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://ramblingso...
http://www.linkedin.com/in/andrew...

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

Dafydd Fontenot

4/15/2009 6:04:00 AM

0

Andrew Timberlake wrote:
> On Wed, Apr 15, 2009 at 7:41 AM, Dafydd Fontenot
> <fontenot.1031@gmail.com> wrote:
>
> 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?

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

Siddick Ebramsha

4/15/2009 6:05:00 AM

0

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


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

Dafydd Fontenot

4/15/2009 6:24:00 AM

0

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

Solved, thank you good sir.

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

Robert Klemme

4/15/2009 7:31:00 AM

0

2009/4/15 Dafydd Fontenot <fontenot.1031@gmail.com>:
> Siddick Ebramsha wrote:
>> Solution :-
>> =A0Dir.new("/").each { |name| puts name if File.directory?( "/" + name) =
}
>
> Solved, thank you good sir.

Here's another one:

puts Dir["/*"].select {|f| test ?d, f}

Cheers

robert

--=20
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestprac...