dafydd
April 15, 2009, 7:41am
1
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?
dafydd
April 15, 2009, 7:59am
2
On Wed, Apr 15, 2009 at 7:41 AM, Dafydd F.
[email protected] 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 T.
http://ramblingsonrails.com
http://www.linkedin.com/in/andrewtimberlake
“I have never let my schooling interfere with my education” - Mark Twain
dafydd
April 15, 2009, 8:04am
3
Andrew T. wrote:
On Wed, Apr 15, 2009 at 7:41 AM, Dafydd F.
[email protected] 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?
dafydd
April 15, 2009, 8:04am
4
Solution :-
Dir.new("/").each { |name| puts name if File.directory?( “/” + name) }
dafydd
April 15, 2009, 8:24am
5
Siddick E. wrote:
Solution :-
Dir.new("/").each { |name| puts name if File.directory?( “/” + name) }
Solved, thank you good sir.
dafydd
April 15, 2009, 9:31am
6
2009/4/15 Dafydd F. [email protected] :
Siddick E. wrote:
Solution :-
Dir.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