From: ara.t.howard@... Date: 2007-05-05T06:50:52+09:00 Subject: Re: Loop through files in a directory On Sat, 5 May 2007, Ben Johnson wrote: > I know this is a nub question, but the documentation on ruby is > terrible. > > How do I loop through all of the files in a directory? > > Thanks for your help. > > -- > Posted via http://www.ruby-forum.com/. > harp:~ > ls dir a b c harp:~ > cat a.rb class Dir def self.ls dir, glob = File.join('**', '**'), &block ret = [] unless block Dir.glob(File.join(dir, glob)) do |entry| block ? block.call(entry) : ret.push(entry) end ret end end Dir.ls 'dir' do |entry| puts entry end entries = Dir.ls 'dir' p entries harp:~ > ruby a.rb dir/a dir/b dir/c ["dir/a", "dir/b", "dir/c"] -a -- be kind whenever possible... it is always possible. - the dalai lama