From: Tim Hunter Date: 2003-01-03T08:51:57+09:00 Subject: Re: Dir.rename? On Thu, 02 Jan 2003 16:23:57 +0000, Useko Netsumi wrote: > how about batch rename using regex? > > "Tim Hunter" 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) 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) }