From: Colin Bartlett Date: 2010-01-08T14:53:44+09:00 Subject: Re: Setting recursion depth About two months ago I adapted Find for my own purposes, to automatically include the depth, and to have a "next" method to make it easier to have two Finds working together. (For comparing two directory structures, etc.) I've put the code here, if you're interested: http://pastie.org/771204 What I'm still undecided on is the appropriate depth for a file! For example: root_file => depth == 0 root_dir => depth == 0 file => depth == 1 or 0 ? (I'm using 1 for now) dir => depth == 1 file => depth == 2 or 1 ? (I'm using 1 for now) The code I'm using for the depth is: (1) at a root, setting the root depth as 0: @depth = 0 @depth_adjuster = -( @root.count( "/" ) + @root.count( "\\" ) ) if @root =~ /(?:(:|((\A|:)[\/\\]+))\z)/ then @depth_adjuster += 1 @root_rem_sep = 0 # xx: / xx:/ etc elsif k = ( @root =~ /(?:[\/\\]+\z)/ ) then @depth_adjuster += 1 @root_rem_sep = k - @root.length # xx/ yy/xx/ etc else @root_rem_sep = 0 # xx yy/xx end (2) at a dir or file which is not a root: @depth = pathv.count( "/" ) + pathv.count( "\\" ) + @depth_adjuster