I have a path string similar to:
/some/long/path/filename.extension
and I need to parse the "filename" part out in ruby
Use suffix parameter of File.basename
method:
# irb
irb(main):001:0> File.basename('/some/long/path/filename.extension', '.*')
=> "filename"
irb(main):002:0> File.basename('/some/long/path/filename.v1.extension', '.*')
=> "filename.v1"
Ref: http://www.ruby-doc.org/core/classes/File.html#M000026
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With