使用Dir.glob从目录中收集文件,现在我想将它们全部移动到一个文件夹中。怎么样?

时间:2013-06-07 04:39:13

标签: file move glob

docx_files = Dir.glob("/Users/jorgeolivero/desktop/*.docx")     # Grabbed all of the .docx files on my desktop.

现在我想将它们移到桌面上名为'target_folder'的文件夹中,我该怎么做?

我尝试了这个,但它返回了'undefined局部变量或方法`fileutils'for main:Object(NameError)'

    require 'fileutils'

    docx_files.each do |x|
      fileutils.mv Dir( 'x', '/Users/desktop/jorgeolivero/target_folder' )
    end

这是我第三周学习Ruby的开始,这是我的第一个项目。如果这个问题看起来很简单,我道歉。再次感谢。

1 个答案:

答案 0 :(得分:0)

试试这个:

require 'fileutils'

docx_files.each do |x|
    FileUtils.mv x, "/Users/desktop/jorgeolivero/target_folder"
end