Skip to content

Instantly share code, notes, and snippets.

@fatbigbright
Created July 16, 2014 23:01
Show Gist options
  • Save fatbigbright/c917d55fea63070123ee to your computer and use it in GitHub Desktop.
Save fatbigbright/c917d55fea63070123ee to your computer and use it in GitHub Desktop.
将sourceDir目录中与sameWithDir目录同名的文件拷贝到targetDir中
require 'fileutils'
def cpSameFile(sourceDir, targetDir, sameWithDir)
Dir.foreach(sameWithDir) do |file|
puts file
filePath = sourceDir + "/" + file
targetPath = targetDir + "/" + file
if file == "." or file == ".." or File.directory?(file)
else
if File.exist?(filePath)
FileUtils.cp filePath, targetPath
end
end
end
end
cpSameFile(ARGV[0], ARGV[1], ARGV[2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment