如何确定别名指向的原始目录?

时间:2022-06-09 22:51:40

I'm working with a directory that's an alias on Mac OS, with Ruby. This is a folder that points to another folder. How can I determine the original directory that this alias points to?

我正在使用一个在Mac OS上使用Ruby的别名目录。这是指向另一个文件夹的文件夹。如何确定此别名指向的原始目录?

In one of my Jenkins jobs, there is an alias called lastStable, which points to the latest stable build folder:

在我的一个Jenkins作业中,有一个名为lastStable的别名,它指向最新的稳定构建文件夹:

如何确定别名指向的原始目录?

path = /Users/steve/.Jenkins/jobs/MyApp/lastStable

lastStable actually points to a folder called 2013-08-06_10_50_49.

lastStable实际上指向一个名为2013-08-06_10_50_49的文件夹。

How can I get this info dynamically in Ruby?

如何在Ruby中动态获取此信息?

2 个解决方案

#1


2  

File.realpath resolves symlinks.

File.realpath解析符号链接。

You could do:

你可以这样做:

File.realpath '/usr/bin/ruby'
#=> "/usr/bin/ruby1.9.3"

#2


1  

You can use the readlink method:

您可以使用readlink方法:

File.readlink(path)

#1


2  

File.realpath resolves symlinks.

File.realpath解析符号链接。

You could do:

你可以这样做:

File.realpath '/usr/bin/ruby'
#=> "/usr/bin/ruby1.9.3"

#2


1  

You can use the readlink method:

您可以使用readlink方法:

File.readlink(path)