From: Bertram Scharpf Date: 2009-09-17T02:09:52+09:00 Subject: Re: Find.find, limited recursion.. Hi, Am Mittwoch, 16. Sep 2009, 06:01:48 +0900 schrieb Brian Wallace: > I'm working on a script that's currently using Find.find to process a > complete directory tree of files and directories .. .however I needed > specific behavior, and I'm still fairly new to this... > > This is what I am currently using, however it will pick up the sub > directories of Dir1 and Dir2 and update the hash... Does anyone see any way > this could be refactored to not update the "process_list" hash with the sub > directories of Dir1 and Dir2? > > -- > > @root_dir = "C:\Root" > > process_list = Hash.new {|h,k| h[k] = []} > > Find.find(@root_dir.to_s) do |f| > f = f.gsub(/\\/,'/') > next if File.stat(f).directory? or f.include?('skipped_filename') > Find.prune if f.include?("skipped_dirname") > d, b = File.split(f) > process_list [d] << b > end Of course I recommend my RbFind tool. It is pure Ruby, no C to compile. Do something like (untested): process_list = Hash.new { |h,k| h[k] = [] } RbFind.run root do prune if dir? next if name =~ /skipped/ process_list[ dirname] << name end Bertram -- Bertram Scharpf Stuttgart, Deutschland/Germany http://www.bertram-scharpf.de