From: Nathan Olberding Date: 2006-05-03T06:16:14+09:00 Subject: Searching Files I'm trying to write a simple script to go through all the files in a specific directory and search for search terms. You should, hypothetically, be able to run: search search_term and find all the applicable results. Here's my code: path = "/home/nathano/notes" notes_dir = Dir.new(path).to_a - ['.', '..'] matches = [] notes_dir.each do |note| ARGV.each do |pattern| file_contents = open(path + "/" + note, "r") file_contents.each do |line| if line.include?(pattern.to_s) matches.push(note) end end end end matches.uniq.each do |x| puts x end It seems to actually work on rare occasion, but obviously it isn't working as expected. I've also tried converting each file to a massive string (readlines.to_s) and "include?"ing that string, but to no avail. Insights? -- Posted via http://www.ruby-forum.com/.