From: Fleck Jean-Julien Date: 2010-01-09T01:00:43+09:00 Subject: Re: Setting recursion depth Hello Stuart, 2010/1/8 Stuart Clarke : > I think this code will work best for me. > > On another matter, is there an easier way to ignore files and just show > folders If you just want the list of the folders from your recursion, you could do >> def search_to_depth(n) >> array = Array.new(n) {|i| '*' + '/*'*i} >> Dir.glob(array) >> end => nil >> search_to_depth(2).collect{|f| File.dirname(f)}.uniq => [".", "Desktop", "Documents", "Downloads", "Library", "Movies", "Music", "Photo Booth", "Pictures", "Public", "Sites"] Note that to get directories present at depth "n", you need to expand files until depth "n+1", that is: def get_non_empty_dir_to_depth(n) search_to_depth(n+1).collect{|f| File.dirname(f)}.uniq end But this method doesn't work if there isn't any file in the directory you are looking for (because we rely on the presence of at least one file at the next level), I don't know if it would matter in your usage. Cheers, -- JJ Fleck PCSI1 Lycée Kléber