Move a folder

D

Dirk Einecke

Hi.

I want to move a folder from "/folder1/foo" to "/folder2/foo". I can not
find a function for moving a folder. Is it right that I've to copy the
src-folder (with FileUtils.cp_r) and then remove this one from the old src?

greeting
Dirk Einecke
 
J

Joel VanderWerf

Dirk said:
Hi.

I want to move a folder from "/folder1/foo" to "/folder2/foo". I can not
find a function for moving a folder. Is it right that I've to copy the
src-folder (with FileUtils.cp_r) and then remove this one from the old src?

FileUtils.mv works for me:

[~] cd tmp
[~/tmp] mkdir folder1
[~/tmp] mkdir folder2
[~/tmp] mkdir folder1/foo
[~/tmp] irb -r fileutils
irb(main):001:0> FileUtils.mv 'folder1/foo', 'folder2/foo'
=> 0
irb(main):003:0> Dir['**/*']
=> ["a.rb", "b.rb", "folder1", "folder2", "folder2/foo"]
 
G

Gennady Bystritsky

You can use File.mv from the standard ftools library:

require 'ftools'
File.mv "/folder1/foo", "/folder2/foo"

For this to work you must make sure that "/folder2" exists.

Gennady.

Hi.

I want to move a folder from "/folder1/foo" to "/folder2/foo". I can
not find a function for moving a folder. Is it right that I've to copy
the src-folder (with FileUtils.cp_r) and then remove this one from the
old src?

greeting
Dirk Einecke

Sincerely,
Gennady Bystritsky
 
D

Dirk Einecke

Hi.

Joel said:
FileUtils.mv works for me:

Okay. Fine.
I was a little bit insecure because in the code of the library you can
read this for mv:

# Moves file(s) +src+ to +dest+.

So I thought it works only for files and not for folders too.
Well - now it works fine and I'm happy :)

greetings
Dirk Einecke
 

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
474,145
Messages
2,570,826
Members
47,371
Latest member
Brkaa

Latest Threads

Top