gpt4 book ai didi

python - 从相对路径确定绝对路径

转载 作者:太空宇宙 更新时间:2023-11-03 15:20:14 27 4
gpt4 key购买 nike

我想在 perl 脚本中将相对路径转换为绝对路径。我的理解是,File::Spec->rel2abs 能够优雅地处理它,但在以下情况下,我没有得到预期的结果

c:\Temp>cat test.pl
use File::Spec;
print File::Spec->rel2abs($ENV{'VS100COMNTOOLS'} . '../../VC/bin/vsvars32.bat');

c:\Temp>perl test.pl
C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\..\..\VC\bin\vsvars32.bat

我期待类似的东西

C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\vsvars32.bat

为 MSWin32-x86-多线程(ActiveState Corp.)构建的 Perl Version v5.6.1

为了让它更清晰,我想实现类似于以下 Python 代码的东西

>>> os.path.abspath(os.path.join(os.environ['VS110COMNTOOLS'], r'..\..\VC\bin\vsvars32.bat'))
'C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\bin\\vsvars32.bat'

最佳答案

You can also do this with the Cwd core module :

use Cwd 'abs_path';
my $abs_path = abs_path($file);

(示例直接取自文档)。

但是,您绝对应该升级您的 Perl。 Perl 5.6.1 实际上是在 12 年前发布的。从那时起,在通用语言和 Windows 支持方面都取得了巨大进步。

关于python - 从相对路径确定绝对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16142921/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com