# Moving a file after processing

**URL:** <https://www.ruby-forum.com/t/moving-a-file-after-processing/180365>\
**Category:** Ruby\
**Created:** [December 18, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/moving-a-file-after-processing/180365 "2009-12-18T14:24:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [December 18, 2009, 2:24pm UTC](https://www.ruby-forum.com/t/moving-a-file-after-processing/180365/1 "2009-12-18T14:24:35Z")

</div>

I’m working on a script and trying to move the file processed to a  
subdir after processing. Here’s an cut down extract of my code…

# example code starts

require ‘ftools’  
basedir = “#{RAILS\_ROOT}/data\_files/resort\_photos/”  
target = “#{RAILS\_ROOT}/data\_files/resort\_photos/processed”

Dir["#{RAILS\_ROOT}/data\_files/resort\_photos/_._"].each do |file|

# process one file at a time

# lets state the filename

puts “Processing: #{file}”

puts “Moving…”  
file.move(basedir + file, target + file) # What should I be doing  
here ?  
puts “Moved…”

end

# example code stops

At present it results in this error…

Moving…  
rake aborted!  
private method `move’ called for #String:0x1030a2f18

thanks

bb

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [December 18, 2009, 2:48pm UTC](https://www.ruby-forum.com/t/moving-a-file-after-processing/180365/2 "2009-12-18T14:48:41Z")

</div>

On 18.12.2009 14:24, bingo bob wrote:

> # example code stops

Ruby’s FileUtils should do what you want:  
[http://ruby-doc.org/core/classes/FileUtils.html#M004331](http://ruby-doc.org/core/classes/FileUtils.html#M004331)

require ‘fileutils’ #this is a guess, but should work  
FileUtils.mv ‘badname.rb’, ‘goodname.rb’

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [December 18, 2009, 3:19pm UTC](https://www.ruby-forum.com/t/moving-a-file-after-processing/180365/3 "2009-12-18T15:19:07Z")

</div>

On 18.12.2009 15:00, bingo bob wrote:

> Sorry if this is a bit simple but something like this then in my  
> example?
> 
> FileUtils.mv file, target + file

That’s the theory, yes.

Mind, you can always fire up irb, or script/console, and fiddle there.  
🙂

---

<div class="post-metadata">

**Author:** ![bingobob](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/e480ec/32.png) [@bingobob](https://www.ruby-forum.com/u/bingobob)\
**Post date:** [December 18, 2009, 3:00pm UTC](https://www.ruby-forum.com/t/moving-a-file-after-processing/180365/4 "2009-12-18T15:00:21Z")

</div>

Sorry if this is a bit simple but something like this then in my  
example?

FileUtils.mv file, target + file

bb
