2013-07-04 100 views
18

我試圖將其所有子文件夾從源文件夾複製到目標文件夾。 下面的代碼似乎沒有做到這一點。我能夠通過使用僅複製文件而不是子文件夾ruby​​將文件夾與子文件夾複製到目標位置

FileUtils.cp_r(Dir["/Volumes/TempData/Collects/Sasi/android/*.*"],"/Volumes/Data/Apps/android") 

什麼是我失蹤?

require 'fileutils' 
puts "operating_system" 
operating_system = gets.chomp 

    if operating_system == "android" then 
    FileUtils.cp_r(Dir["/Volumes/TempData/Collects/Sasi/android/**"],"/Volumes/Data/Apps/android") 
    puts "done" 
    elsif operating_system == "ios" then 
    FileUtils.cp_r(Dir["Volumes/Data/Apps/iOS/CX5/**"],"/Volumes/TempData/Collects/For_CS") 
    puts "done" 
    else 
    puts "do nothing" 
    end 

回答

27

它看起來像FileUtils.copy_entry方法將爲您複製一個目錄樹。 有一個在rubydoc一些信息:http://www.ruby-doc.org/stdlib-2.0/libdoc/fileutils/rdoc/FileUtils.html#method-c-copy_entry

有很多的選擇(如是否保存文件的所有權),但一些快速測試顯示,你可以將源和目標目錄中是這樣的:

FileUtils.copy_entry @source, @destination 
+1

非常感謝,有效! – sasi

+0

也適用於我。 – amorphid

+0

Threadnecromancer,@sasi如果它適合你,請接受答案。 – Pred

相關問題