From: 7stud -- Date: 2007-10-05T21:33:08+09:00 Subject: Re: replace a text in base directory Pokkai Dokkai wrote: > how can replace a text from all files in > "/home/user" directory and sub directories (tree)... Try this: Dir.glob('/Users/me/2testing/dir2/**/*') do |fname| next if File.directory?(fname) File.open("temp.txt", "w") do |temp_file| IO.foreach(fname) do |line| #fname is from outer loop new_line = line.gsub("hello world", "goodbye") temp_file.print(new_line) end File.delete(fname) File.rename("temp.txt", fname) end end ** means to look in the current directory and all subdirectories for the filenames *, where * means all file names(including directory names). -- Posted via http://www.ruby-forum.com/.