recursively finding children

Hi --

I'm trying to get a flattened array of children (down to a certain
depth) of a folder (which is using acts_as_tree).

def recursive_find_depth(depth)
  if self.children.length > 0 and depth != 0
   self.children.each do |child|
    puts child.name
    child.recursive_find_depth(depth -= 1)
   end
  end
end

At the moment, the function 'puts' the right output, i.e. all the
children under a certain folder to a certain depth. However, I
completely stuck about how to get the finished array of children out of
this function (this shouldn't be hierarchal, just a flattened array). If
anyone's wondering what I'm using this for - it's a webdav system
(PROPFIND). Thanks in advance

This is untested, but hopefully will either work or give you some
ideas:

   def recursive_find_depth(depth, list=[])
     unless depth.zero?
       children.each do |child|
         list.push(child.name)
         child.recursive_find_depth(depth-1, list)
       end
     end
     list
   end

David