Created
March 10, 2014 07:02
-
-
Save oa414/9460614 to your computer and use it in GitHub Desktop.
Copy file recursive
This file contains hidden or 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" | |
| source = File.expand_path "umeng_sdk_201312301505_fb_update_analytics/res" | |
| dist = File.expand_path "/Users/mac/Code/Android/Project/MMBaby/res" | |
| puts source | |
| puts dist | |
| puts "=" * 20 | |
| def merge(source, dist) | |
| Dir.foreach(source) do |filename| | |
| next if (filename == ".") or (filename == "..") | |
| source_path = source + "/" + filename | |
| dist_path = dist + "/" + filename | |
| if Dir.exists?(source_path) # 原始资源路径是一个目录,那么在目标路径创建目录,并递归处理 | |
| puts "Is a dir : " + source_path | |
| Dir.mkdir(dist_path) unless Dir.exists?(dist_path) | |
| merge(source_path, dist_path) | |
| else | |
| if File.exists?(dist_path) #原始文件已存在,输出警告,不复制 | |
| puts "Warning: #{dist_path} exists. not copy" | |
| else # 原始文件不存在,拷贝,输出日志 | |
| FileUtils.cp source_path, dist_path | |
| puts "copy #{source_path} to #{dist_path}" | |
| end | |
| end | |
| end | |
| end | |
| merge(source, dist) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment