From: yermej Date: 2007-11-23T01:15:09+09:00 Subject: Re: File fun! How would you... On Nov 22, 2:30 am, Casimir wrote: > 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 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). Sorry, missed the hash part. Borrowing from Robert's solution: require 'find' src = '/' filetypes = [".jpg", ".png", ".gif", ".bmp"] index = Hash.new {|h, k| h[k] = []} Find.find(src) do |path| next unless filetypes.include? File.extname(path) dir, base = File.split path index[dir] << base end Jeremy