(Dang signed emails not going through!)

On Oct 24, 2007, at 12:50 PM, 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.
>
> Csrm
> -- 
> Casimir Pohjanraito
> Art Portfolio: http://csmr.dreamhosters.com

     puts Dir["img/**/*.{png,jpg}"]

I really don't understand what you mean about keeping track of the  
subdirectories.  If you just want to know which directories hold  
images (your code noted both jpg and png), then do this:

     puts Dir["img/**/*.{png,jpg}"].map{|f| File.dirname(f)}.uniq

Or get the count of images in each directory:

     Dir["img/**/*.{png,jpg}"].inject(Hash.new {|h,k|h[k] = 0}) { |h,f|
         h[File.dirname(f)] += 1; h
       }.each do |d,c|
       puts "%5d images in %s"%[c,d]
     end

OK, so that's not exactly "simple", but it is still going to be  
better than the dozens of lines of code you originally posted.  (and  
with a bit of a comment to document the intent, quite easy to follow)

I agree with Robert on the original complexity not being a function  
of using Ruby as the language.

-Rob

Rob Biedenharn		http://agileconsultingllc.com
Rob / AgileConsultingLLC.com