FileUtils.mv

def move_file
from_path=params[:file_name]
to_path=params[:file_name]
to_path[“queue/”]=""
FileUtils.mv “#{from_path}”, “#{to_path}”
redirect_to request.referrer
end

request parameters:

 {"file_name"=>"recordings/WCR-20160409.mp3",
"file_type"=>"to_be_moved",
"page"=>"list_directory"}

i get this error:

Errno::ENOENT

in RecordingsController#move_file

No such file or directory @ sys_fail2 - (recordings/WCR-20160409.mp3, recordings/WCR-20160409.mp3)

around ... FileUtils.mv "#{from_path}", "#{to_path}"

I’m trying to move the file from the recordings/queue/ direcotry up a level to recordings/ I don’t really understand the error it looks like it’s taking both arguments, from_path and to_path and treating them as a combined first argument Anyone?

  def move_file
    from_path=params[:file_name]
    to_path=params[:file_name]
    to_path["queue/"]=""

Have you put a debug print in to check what from_path and to_path are set to?

Colin

params[:file_name], from_path, and to_path all point to the same
object. to verify, check their #object_id.

so if you modify to_path, you also modify the other two. try #dup to
copy an object.

kind regards
--botp

the = assignment operator assigns the values from the right side operand to the left side, it doesn’t change the value of other variables, i dunno what you mean and i dunno what #dup is ~ fugee

No because this action doesn’t print, it moves the file and redirects

how can changing to_path affect the value of from_path ?

Because, as botp pointed out, they are referencing (pointing to) the
same object in memory.
Use
to_path = some function of params[....]
to avoid the problem. In a previous post you said you did not know
what dup does. Perhaps you should find out.

Colin

Like what inconsequential function of params[:file_name] could i use? i tried params[:file_name].to_s but it had no affect

got it working using dup ~ thanks, fugee

got it working using dup ~ thanks, fugee

Hi can some one show me the code example of using dup