def copy(params)
params_desc = {
:root => { :mandatory => false, :type => :string, :default => '.' },
:includes => { :mandatory => false, :type => :string_or_array },
:excludes => { :mandatory => false, :type => :string_or_array },
:dest => { :mandatory => true, :type => :string },
:flatten => { :mandatory => false, :type => :boolean, :default => false },
:dotmatch => { :mandatory => false, :type => :boolean, :default => false }
}
check_parameters(params, params_desc)
root = params[:root]
includes = params[:includes]
excludes = params[:excludes]
dest = params[:dest]
flatten = params[:flatten]
dotmatch = params[:dotmatch]
error "copy 'root' parameter must be an existing directory" unless
File.exists?(root) and File.directory?(root)
error "copy 'dest' parameter must be an existing directory" unless
File.exists?(dest) and File.directory?(dest)
files = filter_files(includes, excludes, root, dotmatch)
puts "Copying #{files.length} file(s) to '#{dest}'"
for file in files
from_file = File.join(root, file)
if flatten
to_file = File.join(dest, File.basename(file))
else
to_file = File.join(dest, file)
end
to_dir = File.dirname(to_file)
FileUtils.makedirs(to_dir) if not File.exists?(to_dir)
FileUtils.cp(from_file, to_file)
end
end