Created
November 16, 2012 08:26
-
-
Save tomraithel/4085449 to your computer and use it in GitHub Desktop.
RUBY: Copy files from one directory into another
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
require 'fileutils' | |
# specify files which should not be copied | |
dont_copy = ['jquery.languageTags.js'] | |
puts "Copying files from FE to BE folder" | |
from_dir = "./../FE/templates/global" | |
to_dir = "./../BE/trunk/htdocs/fileadmin/templates/global" | |
contains = Dir.new(from_dir).entries | |
def copy_with_path(src, dst) | |
FileUtils.mkdir_p(File.dirname(dst)) | |
FileUtils.cp(src, dst) | |
end | |
Dir[from_dir + "/**/*.{js,jpg,jpeg,gif,png,css}"].each do |old_dest| | |
new_dest = old_dest.gsub(from_dir, to_dir) | |
# puts new_dest | |
should_not_copy = dont_copy.any? { |s| new_dest.end_with?(s) } | |
if !should_not_copy | |
puts new_dest | |
copy_with_path(old_dest, new_dest); | |
end | |
end |
Thank you, that was a lot of useful into my project!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks an 👍 Helped me get that file copy done