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?
On Feb 23, 3:39 pm, bwv549 <jtpri...@gmail.com> wrote:
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 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))}$/, '')