Hello Hal, Monday, September 23, 2002, 12:59:46 AM, you wrote: HEF> def getdirs1(root) HEF> dirs=Dir.entries(root) - [".", ".."] HEF> temp = [] HEF> dirs.each {|x| if test(?d,x) then temp << (root+SEP+x) end } HEF> list = [root] + temp HEF> dirs.each {|x| list += getdirs(x) } HEF> list HEF> end HEF> So my two questions are: HEF> 1. What's wrong with getdirs1 that I'm not seeing? HEF> 2. How would you write this in a reasonably HEF> efficient way? of course, use closure to emulate function-in-function behavior: def getdirs(x) list = Array.new recursive_getdir = proc {|root| Dir.foreach(root) {|dir| unless dir=='.' || dir=='..' filename = root+'/'+dir if File.stat(filename).directory? recursive_getdir.call(filename) else list << filename end end } } recursive_getdir.call(x) list end only way to speed up this (on my 1.6.6/cygwin and 1.7.2/visual-c++ platforms) is to add to Dir.entries capability of retrieving filestat information. File.stat() call consumes 80% (!!!) of this script execution time. without this call, this function will work 1.5 times faster than my dir/s! and, matz, how about gc() method on all objects to release excess of memory for such objects as arrays? -- Best regards, Bulat mailto:bulatz / integ.ru