From: William James Date: 2007-09-26T18:00:05+09:00 Subject: Re: concatenate a set of files On Sep 25, 11:04 pm, Lloyd Linklater wrote: > As a ruby nuby I am not yet good enough to golf this, but I went through > the standard books to cobble this together mostly to say that it should > be easy to figure this out. It took me just a few minutes for this so, > if you get the books, it should work for you too. > > my_files = ["f:\\belfry\\1.txt", "f:\\belfry\\2.txt", > "f:\\belfry\\3.txt"] > f = File.new("c:\\joined.txt", "a+") > my_files.each do |f_name| > f_in = File.open(f_name, "r") > f_in.each {|f_str| f.puts(f_str)} > f_in.close > end > f.close If everything will fit in memory at once, then we can proudly say, "We don't need no stinkin' loops!" my_files = ["f:/belfry/1.txt", "f:/belfry/2.txt", "f:/belfry/3.txt"] File.open("c:/joined.txt","w"){|f| f.puts my_files.sort.map{|s| IO.read(s)} }