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!
On Tuesday 22 December 2009, Wood Y. 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!
See the documentation for FileUtils.mv
Stefano
Stefano,
Thanks for the suggestion. I implemented a program with your idea.
Hope it helps Wood
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
You can omit the self. part in
self.run
Ruby is smart enough to not force the developer to use implicit self.