From: Ben Giddings Date: 2005-08-19T01:38:47+09:00 Subject: Re: Idiomatic ruby version of this code? def switch_endings(current_ending, new_ending) files = Dir.glob("*.#{current_ending}") do |filename| File.rename(filename, filename.gsub(/\.#{current_ending}$/, ".#{new_ending}")) end end As for doing both renames at the same time (i.e. swapping the various endings) you can't really do that without using a third temporary ending, so you could do: switch_endings("mp3", "mp3foo") switch_endings("temp", "mp3") switch_endings("mp3foo", "temp") Ben