Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ruby将文件夹的内容从一个位置复制到另一个位置_Ruby_Copy_Directory - Fatal编程技术网

使用ruby将文件夹的内容从一个位置复制到另一个位置

使用ruby将文件夹的内容从一个位置复制到另一个位置,ruby,copy,directory,Ruby,Copy,Directory,我编写此代码是为了将文件从一个位置复制到另一个位置,但我希望将整个文件夹的内容复制到目标位置 我该怎么做?我试过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 Fil

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

我该怎么做?我试过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
将是这件事的好选择

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

摘自鹤嘴锄(1.8),第681页:

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

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