Home » Ruby » Ruby, getting path from path+filename

Ruby, getting path from path+filename

Posted by: admin November 30, 2017 Leave a comment

Questions:

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.

Answers:

Use the Ruby File.dirname method.

File.dirname("C:/Test/blah.txt")
# => "C:/Test"