How can I get the filename from a file path in Ruby?
For example if I have a path of \"C:\\projects\\blah.dll\"
and I just want the \"blah\".
Is
Jonathan Lonowski answered perfectly, but there is something that none of the answers mentioned here. Instead of File::extname, you can directly use a '.*'
to get the file name.
File.basename("C:\\projects\\blah.dll", ".*") # => "C:\\projects\\blah"
But, if you want to get the base file name of any specific extension files, then you need to use File::extname
, otherwise not.