From: Yohanes Santoso Date: 2002-06-12T14:47:38+09:00 Subject: Re: How to read files from a directory foreach? Kurt Euler writes: > All- > > Is there a way to use some type of foreach loop to read in each text > file in a directory, each pass returning a file name and its > contents in two separate strings, until all files have been read? How about a 3-liner? hash={} Dir.entries(".").each{ |file| File.open(file) {|fh| hash[file] = fh.readlines.to_s} if File.stat(file).file? } array=hash.to_a # => array[0][0] = filename, array[0][1] = content > I believe there is a command that reads all file names in a > directory into an array. However, I'd rather see if there's a quick > and dirty way to step through each file without creating (and then > working with) such array. See above. YS.