Move a folder

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

Dirk Einecke wrote:

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”]

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.

···

On May 8, 2004, at 12:38 PM, Dirk Einecke wrote:

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

Hi.

Joel VanderWerf wrote:

Dirk Einecke wrote:

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:

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 :slight_smile:

greetings
Dirk Einecke