Ruby, getting path from path+filename Use the Ruby File.dirname method. File.dirname("C:/Test/blah.txt") # => "C:/Test"