From: "Hal E. Fulton" Date: 2002-09-23T05:59:46+09:00 Subject: Getting a directory tree Hi, all... I have a little method here that gets a list of all directories under a certain starting dir. I considered using "find" but it didn't jump out as being any faster/better than doing it myself. (E.g., extra method call of "prune") This first method works: # # Return an array of directory names starting at the specified root # SEP = File::Separator def getdirs(root) dirs=Dir.entries(root) - [".", ".."] dirs.collect! {|x| test(?d,x) ? root+SEP+x : nil } dirs.compact! list = [root] + dirs dirs.each {|x| list += getdirs(x) } list end but it's slow on my platform/version. I figure if I speed it up on Windows, it will remain fast on other platforms. (Not necessarily, of course.) 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? Cheers, Hal