From: Robert Klemme Date: 2007-10-25T03:15:05+09:00 Subject: Re: Ruby is simple? NooooT! On 24.10.2007 18:48, Casimir P wrote: > On Wed, 24 Oct 2007 09:46:23 -0700, Phlip wrote: > >>>> files = Dir["img/**/*.jpg"] >>> Well technically that does NOT find subdirectories. Call in the >>> disqualifier dogs!!!!!! >> Allow me to draw your attention to the ** >> >> It sweeps subfolders. > But supposedly you cant tell whats what now. Its all just a big blur. You > get all the little images but lose the bigger picture. > > Its what happens when you dont keep track of the subdirectories. Frankly, it's quite unclear to me what you want. When I run your script I see *all* directories printed plus image file names without a path. If that is what you want, then you can do this in "one" line: $ ruby -r find -e 'Find.find(".") {|f| if File.directory? f then puts f elsif /\.(jpg|png)$/i =~ f then puts File.basen ame(f) end }' Or, printed a bit more verbose and added handling of multiple base directories: require 'find' ARGV.each do |dir| Find.find dir do |f| if File.directory? f puts f elsif /\.(?:jpg|png)$/i =~ f puts File.basename(f) end end end Still very concise and readable. The complicatedness of the original code cannot be attributed to Ruby. Cheers robert