Newbie - Moving Contents From Folder to Another

Hi! I'm trying to create a program that will move contents that I've
downloaded (i.e. folder called "Downloads") to another folder ("Songs").
In other words, save mp3's to "Downloads", then run a Ruby script to
move them to folder called "Songs". Can anyone point the way? I'm
playing ftools library but can't find how to do this. Thanks so much!

···

--
Posted via http://www.ruby-forum.com/.

See the documentation for FileUtils.mv

Stefano

···

On Tuesday 22 December 2009, Wood Yee wrote:

>Hi! I'm trying to create a program that will move contents that I've
>downloaded (i.e. folder called "Downloads") to another folder ("Songs").
>In other words, save mp3's to "Downloads", then run a Ruby script to
>move them to folder called "Songs". Can anyone point the way? I'm
>playing ftools library but can't find how to do this. Thanks so much!

Stefano,

Thanks for the suggestion. I implemented a program with your idea.
Hope it helps Wood :slight_smile:

Thanks,
Simeon

#!/usr/bin/env ruby

require 'fileutils.rb'

class SimpleMover
  include FileUtils
  def initialize
    if ARGV.empty?
      puts "Source and Destination arguments required:\n"+
        "$ ruby SimpleMover.rb ~/Downloads/ ~/Music/"
    else
      @source = ARGV[0]
      @destination = ARGV[1]
      self.run
    end
  end
  def run
    mp3s = Dir.glob(@source+"*.mp3");
    if mp3s.empty?
      puts "No mp3s to move."
    else
      puts "Moving these mp3s:\n"+mp3s.join("\n")
      FileUtils.mv mp3s, @destination
    end
  end
end

sm = SimpleMover.new

···

--
Posted via http://www.ruby-forum.com/.

Here the rdoc docu
http://ruby-doc.org/stdlib/libdoc/fileutils/rdoc/index.html

···

--
Posted via http://www.ruby-forum.com/.

You can omit the self. part in

  self.run

Ruby is smart enough to not force the developer to use implicit self.

···

--
Posted via http://www.ruby-forum.com/.