Thanks for replies yermej and Robert! I learn some new agin! IT’s easy!
8)
More comments further down the post… And questions.
On Nov 21, 9:00 am, Casimir [email protected] wrote:
…index in a hash…
…all directories under ‘src’…
[snip!]
yermej wrote this solution:
require ‘find’
src = “/”
index = []
filetypes = [“.jpg”, “.png”, “.gif”, “.bmp”]
Find.find(src) do |path|
index << path if filetypes.include? File.extname(path)
end
Well it works great but the results are in an array and would require
further processing before files would be in an hash… with path as keys
(which my orig post didn’t specify though).
Robert K. wrote:
EXTENSIONS = %w{jpg png gif bmp}
index = Hash.new {|h,k| h[k]=[]}
Dir[“**/*.{#{EXTENSIONS.join(‘,’)}}”].each do |f|
dir, base = File.split f
index[dir] << base
end
Wow. That is snappy.
I, too, was annoyed when I couldnt assign stuff into the Hash with <<.
I dont know why. It has more characters than “arr[key]=val”. You could
save almost 2 lines with the = version. It looks better I guess. I
couldnt bend ruby like that tho, over. Haha!
I also like how you handle the assignment of the split file path with
“dir, base = File.split f”.
And I have no idea what the {#{EXTENSIONS.join(‘,’)}} is all about! IRB
just gave me *'s.
lol I am just a dummy! Hahaha!