【问题标题】:How do I get the path without the last folder using ruby? [duplicate]如何使用 ruby​​ 获取没有最后一个文件夹的路径? [复制]
【发布时间】:2016-05-23 13:45:06
【问题描述】:

给出的例子:

我的路径是(由 Dir.pwd 给出)“D:/home/usr/documents/text files/2016”

在没有最后一个子文件夹的情况下获取路径的简单方法是什么。

结果应该是:“D:/home/usr/documents/text files”

目前我这样做 path = Dir.pwd.reverse.partition("/")[-1].reverse

有效,但我想我错过了更好的方法。

提前致谢!

【问题讨论】:

    标签: ruby directory subdirectory


    【解决方案1】:
    File.expand_path("..", Dir.pwd)
    

    【讨论】:

      猜你喜欢
      • 2015-01-17
      • 1970-01-01
      • 2022-09-23
      • 2016-07-20
      • 2011-03-11
      • 2012-11-30
      • 1970-01-01
      • 2011-05-17
      • 2016-03-08
      相关资源
      最近更新 更多