【问题标题】:copy contents of a folder from one location to another using ruby使用 ruby​​ 将文件夹的内容从一个位置复制到另一个位置
【发布时间】:2013-07-02 09:02:58
【问题描述】:

我编写此代码是为了将文件从一个位置复制到另一个位置,但我想将整个文件夹的内容复制到目标位置。

我该怎么做?我尝试了 file.copy dir,但它不起作用。

require 'ftools'
fname = gets.chomp

if fname == "android" then
  File.copy "/Volumes/TempData/Collects/Sasi/android/grade.rb","/Volumes/Data"
elsif fname == "ios" then
  File.copy"/Volumes/Sasi/ios/grade.rb","/Volumes/TempData/Sasi/KugaViewr/grade.rb"
else 
  puts "do nothing"
end

【问题讨论】:

    标签: ruby copy directory


    【解决方案1】:

    FileUtils#copy_entry 会是这个东西的不错选择。

    将文件系统条目 src 复制到 dest。如果 src 是一个目录,这个方法递归地复制它的内容。此方法保留文件类型,c.f.符号链接、目录...(FIFO、设备文件等尚不支持)

    【讨论】:

      【解决方案2】:

      来自镐 (1.8),第 681 页:

      现在推荐使用 FileUtils 库而不是 ftools。

      如果您出于某种原因必须使用 ftools,请参阅 ftools solution

      【讨论】:

        猜你喜欢
        • 2022-12-05
        • 1970-01-01
        • 2021-12-18
        • 2011-05-03
        • 1970-01-01
        • 1970-01-01
        • 2015-01-30
        • 2013-05-02
        相关资源
        最近更新 更多