Created
October 5, 2010 17:01
-
-
Save jsmecham/611907 to your computer and use it in GitHub Desktop.
Dir.clone! for Ruby
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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