moving a file after processing

B

bingo bob

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
 
P

Phillip Gawlowski

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

Ruby's FileUtils should do what you want:
http://ruby-doc.org/core/classes/FileUtils.html#M004331

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

bingo bob

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

FileUtils.mv file, target + file

bb
 
P

Phillip Gawlowski

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. :)
 

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,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top