Dir.rename?

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten

···


http://fastmail.fm - Email service worth paying for. Try it for free

coma_killen@fastmail.fm wrote:

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten


http://fastmail.fm - Email service worth paying for. Try it for free

Keeping in mind that a dir is just a file…

require “ftools”
File.move(“old”,“new”)

Regards,

Dan

File.rename(old, new)

···

On Fri, 03 Jan 2003 05:10:29 +0900, coma_kille wrote:

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten

or even

File.rename(“old”, "new)

:wink:

Regards,

/Robert

···

On Fri, 3 Jan 2003, Daniel Berger wrote:

coma_killen@fastmail.fm wrote:

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten


http://fastmail.fm - Email service worth paying for. Try it for free

Keeping in mind that a dir is just a file…

how about batch rename using regex?

“Tim Hunter” cyclists@nc.rr.com wrote in message
news:pan.2003.01.02.15.08.26.64569@nc.rr.com

···

On Fri, 03 Jan 2003 05:10:29 +0900, coma_kille wrote:

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten

File.rename(old, new)

Robert Feldt wrote:

···

On Fri, 3 Jan 2003, Daniel Berger wrote:

coma_killen@fastmail.fm wrote:

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten


http://fastmail.fm - Email service worth paying for. Try it for free

Keeping in mind that a dir is just a file…

or even

File.rename(“old”, "new)

:wink:

Regards,

/Robert

D’oh! Thinking too much in *nix, I guess. :slight_smile:

Dan

Hmmm…I think you’d want to loop over the parent directory and rename
each entry individually. I don’t feel good about renaming entries in the
directory while I’m looping over it, so my inclination would be to collect
the directory entries in an array with Dir. and then loop over the array
with Array.each. Something like this (NOT tested!)

Dir[‘*’].each { |old|
next if old == ‘.’ || old == ‘…’ || !FileTest.directory(old) next
unless /re/.match(old) # skip entries that don’t
# match your regexp
new = old.sub(re,sub) # create new name File.rename(old,new) #
File.rename(old,new)
}

···

On Thu, 02 Jan 2003 16:23:57 +0000, Useko Netsumi wrote:

how about batch rename using regex?

“Tim Hunter” cyclists@nc.rr.com wrote in message
news:pan.2003.01.02.15.08.26.64569@nc.rr.com

On Fri, 03 Jan 2003 05:10:29 +0900, coma_kille wrote:

Hi,

Is there some easy way to rename directories from Ruby code?

Like Dir.rename(old, new)?

Regards,

Karsten

File.rename(old, new)