小编BPr*_*rov的帖子

检查文件是否比 Ruby 中的其他文件更新?

在 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:in block 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)

ruby file-io

-1
推荐指数
1
解决办法
496
查看次数

标签 统计

file-io ×1

ruby ×1