Editing Topic: RCR151 Project: RCR | RCRchive home

RCR 151: Dir.recurse

submitted by anonymous on 2003-08-21 10:57:47


This is a legacy RCR. If this is your RCR, please resubmit it using the new format and process.


Simple enough, a "recurse" method for class Dir. This would take a block, and call the block for every subdirectory of the given (or current, in the absence of an argument) directory. Optionally, it could take a "max depth" argument. The absolute path of each directory recursed into would be passed into the block. So, given a directory setup like
       /dir
      /    
  subdir   subdir2
   /   
subsub  subsub2
Doing
Dir.recurse(".") { |d| puts d}
Would print
/dir
/dir/subdir
/dir/subdir2
/dir/subdir/subsub
/dir/subdir/subsub2
With a maxdepth argument,
Dir.recurse("/dir", 1) {|d| puts d}
would print
/dir
/dir/subdir
/dir/subdir2


Back to RCRchive.


RCR Submission page and RCRchive powered by Ruby, Apache, RuWiki (modified), and RubLog