From: "Srinath A." Date: 2009-02-25T14:35:58+09:00 Subject: Re: append static text for all files in a directory The code below was working fine , but deleting the first line in the files and writing the added one : Dir.glob("application.rb") do |file| File.open(file,"r+") do |f| puts file f.puts "Commenting is very common style.\nCommenting helps more easy readability" end end how can we prepend text in file with out deleting the existing content ?? thanks !! Simon Krahnke wrote: > * Srinath A. (07:16) schrieb: > >> How to append static text for all files in application . >> I want to append comment lines on top of each file in app/controllers/ > > Appending is "inserting" text at the end of the file. If you want to > modify something before the end you got to read it all in, do your > changes, and write it out again. > > If your Files are small enough to be read in whole, it's quite easy in > Ruby: > > content = File.read(filename) > File.open(filename, "w") do | f | > f << "# comment\n" > f << content > end > > mfg, simon .... untested -- Posted via http://www.ruby-forum.com/.