Newbie - Moving Contents From Folder to Another

W

Wood Yee

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!
 
S

Stefano Crocco

|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
 
S

Simeon Willbanks

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
 
M

Marc Heiler

You can omit the self. part in

self.run

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top