我要使用哪些Perl模块从Windows上的相对路径获取绝对路径(包括文件名)? [英] What Perl module(s) do I use to obtain an absolute path (including filename) from a relative one on Windows?

查看:411
本文介绍了我要使用哪些Perl模块从Windows上的相对路径获取绝对路径(包括文件名)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只能想象我没有正确搜索;这似乎是一个显而易见的问题.如果这是重复的话,我深表歉意.

I can only imagine I'm not searching correctly; this seems like an obvious question to be asked here. My apologies if this is a duplicate.

我正在编写一个Perl程序,它将文件名作为命令行参数.我需要将文件名(或带有相对路径的文件名)转换为绝对路径(专门用于Win32 :: OLE).

I'm writing a Perl program that will take a filename as a command-line argument. I need to convert the filename (or the filename with a relative path attached) to an absolute path (specifically to work with Win32::OLE).

我尝试使用 Cwd 的"abs_path",它几乎可以满足我的要求,但是它使用Unix样式的路径而不是Win32路径返回它.

I tried using Cwd's 'abs_path', and that almost does what I want, but it returns it using a Unix-style path instead of a Win32 one.

是否有一个将转换路径的模块,或者也许是一个首先使用的更好的模块?

Is there a module that will convert the path, or perhaps a better module to use in the first place?

推荐答案

我使用文件中的rel2abs: :规范.但是,您必须要小心:这可能会从Cwd调用getdcwd,并且它将假定您想要当前驱动器的当前工作目录.如果文件在其他驱动器上,则必须自己进行修复或提供第二个参数来设置基本路径.

I use rel2abs from File::Spec. You have to be careful though: that might call getdcwd from Cwd, and it will assume that you want the current working directory for the current drive. If the file is on some other drive, you'll have to fix that up yourself or supply the second argument to set the base path.

这篇关于我要使用哪些Perl模块从Windows上的相对路径获取绝对路径(包括文件名)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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