----- Original Message ----- 
From: <dblack / candle.superlink.net>
To: "ruby-talk ML" <ruby-talk / ruby-lang.org>
Sent: Sunday, September 22, 2002 4:34 PM
Subject: Re: Getting a directory tree


> You've got a call to getdirs instead of a recursive call to getdirs1.

Dumb.

> Also, you're testing x, but you need to test root+SEP+x.  (Otherwise
> the test will be in the current directory.)  

Dumber. 

So that's why I had that "unnecessary" chdir and getwd 
in the other version... :)

> And... you should do
> temp.each, not dirs.each, I think.

Dumbest. 

Why do I post on days like this?

> Here's a nice slow revised version, which looks better than it
> performs :-)
>
>   def getdirs_d1(root)
>     dirs=Dir.entries(root) - [".", ".."]
>     temp = dirs.map {|d| root+SEP+d}.select {|d| test(?d,d)}
>     temp + temp.map {|x| getdirs1(x) }
>   end

I'll probably go with this because it looks nice.

In connection with my being brain-dead today, I *did*
discover a way to double the speed of this search.

I call this new technique "Don't Invoke the Method Twice
When You Don't Really Need To."  :)

Hal