Skip to content

Instantly share code, notes, and snippets.

@jsmecham
Created October 5, 2010 17:01
Show Gist options
  • Save jsmecham/611907 to your computer and use it in GitHub Desktop.
Save jsmecham/611907 to your computer and use it in GitHub Desktop.
Dir.clone! for Ruby
class Dir
def self.clone!(source, destination, exclude)
exclude = ["^\\.{1,2}$"].concat(exclude).uniq
FileUtils.mkdir destination unless Dir.exists? destination
Dir.foreach(source) do |file|
next if exclude.detect { |pattern| file.match(/#{pattern}/i) }
source_path = File.join(source, file)
destination_path = File.join(destination, file)
if File.directory?(source_path)
FileUtils.mkdir(destination_path)
clone! source_path, destination_path, exclude
else
FileUtils.cp(source_path, destination_path)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment