在 Ruby 中,如何在复制之前检查文件是否比目标新?
我在Ruby-doc.org 中找到了FileUtils.uptodate?,但它似乎不起作用。
运行时出现此错误消息:
/Users/bprov/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/fileutils.rb:148:in
uptodate?': undefined methodeach' for "/Users/bprov/folder2/homecontroller":String (NoMethodError ) 来自 Test_Copy.rb:11:inblock in <main>' from Test_Copy.rb:6:inforeach' 来自 Test_Copy.rb:6:in `'
我有这样的事情:
require 'fileutils'
$sourcepath = "/Users/bprov/railsbridge"
$destinationpath = "/Users/bprov/folder2"
Dir.foreach($sourcepath) do |file|
if (file =~ /^\./ )
# Do nothing
else
puts file
if FileUtils.uptodate?($sourcepath + "/" + file, $destinationpath + "/" + file)
# Do nothing
else
# If newer
FileUtils.cp($sourcepath + "/" + file, $destinationpath + "/" + …Run Code Online (Sandbox Code Playgroud)