Moving a file after processing

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

···

--
Posted via http://www.ruby-forum.com/.

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'

···

On 18.12.2009 14:24, bingo bob wrote:

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

--
Phillip Gawlowski

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

FileUtils.mv file, target + file

bb

···

--
Posted via http://www.ruby-forum.com/.

That's the theory, yes.

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

···

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

--
Phillip Gawlowski