开发者

Perl alternative to Cwd::abs_path for symbolic links

开发者 https://www.devze.com 2023-03-27 14:31 出处:网络
My Perl app receives relative paths to files and arguments and then converts them to absolute paths.I had been using Cwd::开发者_开发百科abs_path($fileName) just fine, but now I need to support symbol

My Perl app receives relative paths to files and arguments and then converts them to absolute paths. I had been using Cwd::开发者_开发百科abs_path($fileName) just fine, but now I need to support symbolic links and I find that abs_path will give me the absolute path to the original file.

What I need is an alternative to Cwd::abs_path that when given a relative path to a symlink will convert it to an absolute path to that same symlink. Any recommendations?

Example:

/originals/myfile1
/links/myfile1link -> /originals/myfile1

> cd /links
> perl converter.pl /myfile1link
> output: /links/myfile1link


File::Spec->rel2abs does not do any system checks, so it won't resolve symlinks.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号