FileUtils.mv

37 views
Skip to first unread message

fugee ohu

unread,
Apr 18, 2016, 10:50:14 AM4/18/16
to Ruby on Rails: Talk
  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?

Colin Law

unread,
Apr 18, 2016, 11:32:07 AM4/18/16
to Ruby on Rails: Talk
On 18 April 2016 at 15:50, fugee ohu <fuge...@gmail.com> wrote:
> 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

> 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?
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/efc084af-3b60-4ebe-9b0d-cdad52b595b7%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

botp

unread,
Apr 18, 2016, 12:13:37 PM4/18/16
to rubyonra...@googlegroups.com
On Mon, Apr 18, 2016 at 10:50 PM, fugee ohu <fuge...@gmail.com> wrote:
> 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
>

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

fugee ohu

unread,
Apr 18, 2016, 1:29:21 PM4/18/16
to Ruby on Rails: Talk

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

fugee ohu

unread,
Apr 18, 2016, 1:38:39 PM4/18/16
to Ruby on Rails: Talk
No because this action doesn't print, it moves the file and redirects

fugee ohu

unread,
Apr 18, 2016, 2:07:39 PM4/18/16
to Ruby on Rails: Talk


On Monday, April 18, 2016 at 11:32:07 AM UTC-4, Colin Law wrote:

how can changing to_path affect the value of from_path ?

Colin Law

unread,
Apr 18, 2016, 3:53:44 PM4/18/16
to Ruby on Rails: Talk
On 18 April 2016 at 19:07, fugee ohu <fuge...@gmail.com> wrote:
> ...
> 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

fugee ohu

unread,
Apr 18, 2016, 6:56:53 PM4/18/16
to Ruby on Rails: Talk

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

fugee ohu

unread,
Apr 18, 2016, 7:32:17 PM4/18/16
to Ruby on Rails: Talk


On Monday, April 18, 2016 at 3:53:44 PM UTC-4, Colin Law wrote:

got it working using dup ~ thanks, fugee

fugee ohu

unread,
Apr 18, 2016, 7:32:43 PM4/18/16
to Ruby on Rails: Talk


On Monday, April 18, 2016 at 12:13:37 PM UTC-4, bot Peña wrote:
Reply all
Reply to author
Forward
0 new messages