Skip to content

Instantly share code, notes, and snippets.

@tomraithel
Created November 16, 2012 08:26
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomraithel/4085449 to your computer and use it in GitHub Desktop.
Save tomraithel/4085449 to your computer and use it in GitHub Desktop.
RUBY: Copy files from one directory into another
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
@dayneo
Copy link

dayneo commented Dec 3, 2020

Thanks an 👍 Helped me get that file copy done

@Ak4ts
Copy link

Ak4ts commented Mar 6, 2024

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