Ruby, getting path from path+filename

前端 未结 2 1141
轻奢々
轻奢々 2020-12-30 18:15

Programming language: Ruby 1.9

Problem String: C:/Test/blah.txt
to C:/Test/

I know it\'s an easy question, but Google and the R

相关标签:
2条回答
  • 2020-12-30 18:51

    More versatile would be the Ruby Pathname class:

    require 'pathname'
    
    pn = Pathname.new("C:/Test/blah.txt")
    p pn.dirname.to_s + Pathname::SEPARATOR_LIST
    

    which gives C:/Test/.

    0 讨论(0)
  • 2020-12-30 18:52

    Use the Ruby File.dirname method.

    File.dirname("C:/Test/blah.txt")
    # => "C:/Test" 
    
    0 讨论(0)
提交回复
热议问题