关于NTFS重新解析点(符号链接/目录连接)的路径规范化? [英] Path normalization with respect to NTFS reparse points (symlinks/directory junctions)?

查看:171
本文介绍了关于NTFS重新解析点(符号链接/目录连接)的路径规范化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不幸的是,我在Windows上并且需要POSIX realpath

Unfortunately, I'm on Windows and I need POSIX realpath.

假设CMD批处理脚本中有一个dirpath变量:

Suppose that there's a dirpath variable in a CMD batch script:

FOODIR=D:/tmp/foo/bar/quux

其中目录路径的一个或多个中间组件为符号链接(在Microsoft看来是目录连接):

where one or more middle components of the dirpath are symlinks (directory junctions in Microsoft parlance):

[/cygdrive/d/tmp]$ cmd /C dir /Ad /l
 ...
 Directory of D:\tmp
...
2014-12-10  16:44    <SYMLINKD>     foo [D:\storage\foo.canonical]

如何编写将转换的函数%FOODIR% D:/storage/foo.canonical/bar/quux

How to write a function which will transform %FOODIR% into D:/storage/foo.canonical/bar/quux?

欢迎使用任何解决方案。

Any solutions welcome.

推荐答案

GetFinalPathNameByHandle 为我工作。

或者使用Powershell 5+,您可以遍历路径并解析每个文件夹。在('Junction','SymbolicLink')中检查 .LinkType并使用 .Target [0] 和可选分辨率相对符号链接。

Alternatively with Powershell 5+ you may traverse path up and resolve each folder. Check for .LinkType in ('Junction', 'SymbolicLink') and use .Target[0] with optional resolution for relative symlinks.

这篇关于关于NTFS重新解析点(符号链接/目录连接)的路径规范化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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