From: Robert Klemme Date: 2010-01-08T07:00:05+09:00 Subject: Re: Setting recursion depth On 01/07/2010 09:17 PM, Stuart Clarke wrote: > Hi all, > > I have done some Googling regarding setting the depth of recursive > search in a ruby script and all I have identified is File-Find. Is this > all that can help me? > > Basically I want to be able to specify the depth my script will work so > if the depth is 4, the script will look at all items from the root to 4 > folders deep e.g > > Root > Folder 1 > Folder 2 > Folder 3 > > Any input is much appreciated. You can use Find.prune for this. Try: ruby19 -r find -e 'Find.find("/usr/local"){|f| p f; Find.prune if f.scan(%r{/}).size > 4}' ------------------------------------------------------------- Find#prune prune() From Ruby 1.9.1 ------------------------------------------------------------------------ Skips the current file or directory, restarting the loop with the next entry. If the current file is a directory, that directory will not be recursively entered. Meaningful only within the block associated with Find::find. See the +Find+ module documentation for an example. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/