From: bwv549 Date: 2009-02-24T07:39:25+09:00 Subject: what is best idiom to remove file extension What is the most concise, bulletproof idiom for removing the file extension from a file? Maybe I've missed something obvious that everyone else uses... Here's what I usually do: This is what I usually use if I want bulletproof: filename.sub(/#{Regexp.escape(File.extname(filename))}$/, '') I use something like this when I want something quick: filename.sub(/\.\w$/,'') One could imagine doing something like this, but it is comical how much code it takes: File.join( File.dirname(filename), File.basename(filename, File.extname(filename))) What do you use for this (seemingly) trivial task? Thanks, John