Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

parsing string pathname with ruby

I have a path string similar to:

/some/long/path/filename.extension

and I need to parse the "filename" part out in ruby

like image 805
sysconfig Avatar asked Dec 03 '22 01:12

sysconfig


1 Answers

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

like image 144
qingbo Avatar answered Dec 11 '22 05:12

qingbo