From: William James Date: 2007-09-26T17:45:14+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"] Even under windoze, Ruby lets you use the forward slash in paths. > 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 > > disclaimer: I apologize for the look and feel of the 'compiled > language' approach. I am still a n00b to the ruby way. :) Let Ruby close the files for you. my_files = ["f:/belfry/1.txt", "f:/belfry/2.txt", "f:/belfry/3.txt"] File.open( "c:/joined.txt", "w" ){|f_out| my_files.each {|f_name| File.open(f_name){|f_in| f_in.each {|f_str| f_out.puts(f_str) } } } }