#!/usr/bin/env ruby -w require 'fileutils' def usage puts "usage: #{File.basename( __FILE__ )} source_directory destination_directory" end if ARGV.length < 2 then usage exit( 1 ) else source_directory = ARGV[0].dup # FileUtils.cp_r uses the syntax "source_directory/." when specifying the source directory when # what is desired is to copy all contents of the source directory (rather than the directory itself). # Therefore we need to ensure that the source_directory variable we'll be using as an argument # to FileUtils.cp_r ends in '/.' ('\.' on Windows, and whatever else is appropriate on other OS's). Dot = '.' Slash_dot = "#{File::SEPARATOR}#{Dot}" if source_directory[-2..-1] != Slash_dot then if source_directory[-1..-1] != File::SEPARATOR then source_directory << Slash_dot else source_directory << Dot end end destination_directory = ARGV[1] end FileUtils.cp_r( source_directory, destination_directory, :preserve => TRUE )