如何从Ruby中的文件路径获取没有扩展名的文件名

问题描述:

如何从 Ruby 中的文件路径获取文件名?

How can I get the filename from a file path in Ruby?

例如,如果我的路径为 "C:\projects\blah.dll" 而我只想要blah".

For example if I have a path of "C:\projects\blah.dll" and I just want the "blah".

Ruby 中是否有 LastIndexOf 方法?

Is there a LastIndexOf method in Ruby?

require 'pathname'

Pathname.new('/opt/local/bin/ruby').basename
# => #<Pathname:ruby>

我已经很长时间没有成为 Windows 用户了,但是路径名 rdoc 说它在 Windows 上没有目录名称分隔符的问题.

I haven't been a Windows user in a long time, but the Pathname rdoc says it has no issues with directory-name separators on Windows.