如何从irb获取当前工作目录的绝对路径 [英] how to get the current working directory's absolute path from irb

查看:38
本文介绍了如何从irb获取当前工作目录的绝对路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 上运行 Ruby,但我不知道这是否会有所作为.我想要做的就是获取当前工作目录的绝对路径.这可能来自irb吗?显然从脚本可以使用 File.expand_path(__FILE__)

I'm running Ruby on Windows though I don't know if that should make a difference. All I want to do is get the current working directory's absolute path. Is this possible from irb? Apparently from a script it's possible using File.expand_path(__FILE__)

但是从 irb 中,我尝试了以下操作并收到权限被拒绝"错误:

But from irb I tried the following and got a "Permission denied" error:

File.new(Dir.new(".").path).expand

推荐答案

Dir.pwd 似乎可以解决问题.

http://ruby-doc.org/core/Dir.html#method-c-pwd

这篇关于如何从irb获取当前工作目录的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆