Thursday, February 26, 2009

renaming files on Mac OS X with ruby

So, for example you have bunch of ".htm" files that you want to rename to ".html"

You need to open your Terminal.app "cd" to the directory where you files are and run this command:
ruby -e "Dir.glob('*.htm').each{|file| File.rename(file,file.gsub('.htm', '.html'))}"

If you want it to work for a current and all recursive directories you need to make a simple change:
ruby -e "Dir.glob('**/*.htm').each{|file| File.rename(file,file.gsub('.htm', '.html'))}"

No comments: