DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Eric has posted 2 posts at DZone. View Full User Profile

Copy To A Target Directory And Filter Files

10.07.2008
| 6048 views |
  • submit to reddit
        # not the best code around but worked for my usage,...
require 'fileutils'
target = "../custom_code/"
FileUtils.mkdir(target) unless File.exist?(target)

require "rake"
FileList['**/*.java'].each do |source|
  file_name = File.basename(source)
  target_dir = target + File.new(source).path.sub(file_name, '')
  makedirs target_dir 
  cp_r source, target_dir + file_name, :verbose => true
end