# Newbie - Moving Contents From Folder to Another

**URL:** <https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610>\
**Category:** Ruby\
**Created:** [December 22, 2009, 10:34pm UTC](https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610 "2009-12-22T22:34:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 22, 2009, 10:34pm UTC](https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610/1 "2009-12-22T22:34:43Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 22, 2009, 10:53pm UTC](https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610/2 "2009-12-22T22:53:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 23, 2009, 12:13am UTC](https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610/3 "2009-12-23T00:13:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 23, 2009, 12:45am UTC](https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610/4 "2009-12-23T00:45:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![woodyee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/43a26b/32.png) [@woodyee](https://www.ruby-forum.com/u/woodyee)\
**Post date:** [December 23, 2009, 12:46am UTC](https://www.ruby-forum.com/t/newbie-moving-contents-from-folder-to-another/180610/5 "2009-12-23T00:46:56Z")

</div>

You can omit the self. part in

self.run

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