0
    class Desktop

      # grab the names of items on the desktop
      desktop_content = Dir.entries("/Users/jorgeolivero/desktop")

      def initialize(desktop_content)
        @desktop_content = desktop_content
      end

      def initlialize(select)
        arr.select { |x| x.include? "y"}
      end

      def initialize(desktop_files)
        @desktop_files = desktop_files
      end

      # grabs the files from the desktop_content array
      desktop_files = desktop_content.select { |c| c.include? '.'}

      puts desktop_files

      desktop_files.each { |files| File.rename('/Users/jorgeolivero/desktop/***feed array items here***', '/Users/jorgeolivero/desktop/folder/***feed array items here***') }

    end

我的直觉告诉我,这对你们中的一些人来说可能看起来很痛苦,所以请知道这是我第一次尝试应用程序。所以如果你能记住那个过程,你就会明白我现在是多么“卡住”。

我想用一个命令将“desktop_files”数组中的所有项目移动到一个文件夹中。最后一段代码显示了我正在尝试做的事情,但我不知道如何将每个文件名提供到每个路径的末尾(如 ***s 所示)。

非常感谢。

4

1 回答 1

0

You can use the following code for copy all your files:

require 'fileutils'

FileUtils.mv Dir['/Users/jorgeolivero/desktop/*'], 'dest folder'

You don't need to create a class for it. You can run this code on irb or put in a single file.

PS: Ruby doesn't accept multiple initializers for a class.

于 2013-06-06T20:35:44.507 回答