Hi -- On Tue, 2 Oct 2007, 7stud -- wrote: > Remco Hh wrote: >> >> I want to search in a directory for files, matching a certain regular >> expression. The script should not return true or false, but should give >> me a list (array) of filenames which are found. >> > > Try something like this: > > results = [] > > Dir.foreach("./programs_ruby") do |filename| > if filename.index("mod") > results << filename > end > end > > p results A little more concise: results = Dir.entries("./programs_ruby").grep(/mod/) Or you could do: results = Dir["*mod*"] to automatically exclude hidden files, if that's desired. David -- Upcoming training from Ruby Power and Light, LLC: * Intro to Ruby on Rails, Edison, NJ, October 23-26 * Advancing with Rails, Edison, NJ, November 6-9 Both taught by David A. Black. See http://www.rubypal.com for more info!