Reputation: 1105
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 Ruby quickref for File
have no solution for me.
And I have no experience with Regex.
Upvotes: 105
Views: 72109
Reputation: 806
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/
.
Upvotes: 2
Reputation: 176382
Use the Ruby File.dirname
method.
File.dirname("C:/Test/blah.txt")
# => "C:/Test"
Upvotes: 192