From: Richard Zidlicky Date: 2003-08-19T06:49:40+09:00 Subject: Re: [RCR] Dir.recurse On Sun, Aug 17, 2003 at 04:16:36AM +0900, Jim Bob wrote: > I think it'd be useful (and worthwhile) to have a Dir.recurse method. > This method would take two optional arguments and a mandatory block. The > first argument, if given, is the directory to start recursing from. If > it is omitted, then recursion starts from the current directory. The > second argument, if given, specifies a maximum depth to recurse to. If > omitted, recursion would go as deep as possible. > > The method would change to each directory under the current working > directory in turn, and also pass each directory's name to the block. The > block would be executed once for each directory. > > So, given a directory tree like > somedir > / \ > sub sub2 > / \ > ssub ssub2 > > 'Dir.recurse("/somedir") { |x| puts x }' would print: > /somedir > /somedir/sub > /somedir/sub/ssub > /somedir/sub/ssub2 > /somedir/sub2 Did you see the "find" module? Should be able to do all this even though the use of prune to limit max depth might not be optimal for performance reasons. Richard