Hi -- On Mon, 23 Sep 2002, Hal E. Fulton wrote: > Here's one new version. It DOES NOT work, and I'm > not sure why yet. > > def getdirs1(root) > dirs=Dir.entries(root) - [".", ".."] > temp = [] > dirs.each {|x| if test(?d,x) then temp << (root+SEP+x) end } > list = [root] + temp > dirs.each {|x| list += getdirs(x) } > list > end > > So my two questions are: > 1. What's wrong with getdirs1 that I'm not seeing? > 2. How would you write this in a reasonably > efficient way? Sticking to question #1 for the moment... :-) You've got a call to getdirs instead of a recursive call to getdirs1. Also, you're testing x, but you need to test root+SEP+x. (Otherwise the test will be in the current directory.) And... you should do temp.each, not dirs.each, I think. 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 Maybe something could be done with it or an amalgam of them. David -- David Alan Black | Register for RubyConf 2002! home: dblack / candle.superlink.net | November 1-3 work: blackdav / shu.edu | Seattle, WA, USA Web: http://pirate.shu.edu/~blackdav | http://www.rubyconf.com