From: matt@... (matt neuburg) Date: 2006-11-27T05:25:14+09:00 Subject: Re: How to re-name a file from Ruby script Li Chen wrote: > Hi all, > > I have a folder containing many files with format > LIPID5-2.001 > LIPID5-2.002 > .. > LIPID5-2.200 > > I want to change all of them into > LIPID5-3.001 > LIPID5-3.002 > .. > LIPID5-3.200 > > I write a script as follows. Based on the screen output the filename is > changed. But I go to the same folder and find the original file > LIPID5-2.001 is still there and there is no file called LIPID5-3.001. > Any comments? > > Thanks, > > Li > > ## > path='C:\Ruby\self' > > Dir.entries(path).each do |filename| > > if filename=~/(LIPID5-2)(\.\w+)/i > p filename.gsub!(/LIPID5-2/,'LIPID5-3') > end You're changing a variable called filename but you're not also talking to the filesystem and asking it to change the name of the file on disk. For that, you want something like File.rename. m. -- matt neuburg, phd = matt@tidbits.com, http://www.tidbits.com/matt/ Tiger - http://www.takecontrolbooks.com/tiger-customizing.html AppleScript - http://www.amazon.com/gp/product/0596102119 Read TidBITS! It's free and smart. http://www.tidbits.com