如何获得路口的目标路径?
How to get target path of a junction?
我有一个文件夹C:\the Junction\test
,其实是一个路口,真实路径(目标)是D:\the real\path\to\the folder
.
如何在 VBScript 中找到真正的目标路径?
试试这个代码:
Set p = CreateObject("WScript.Shell").Exec("cmd /c @echo off & for /f ""tokens=5,6"" %a IN ('dir ""c:\the junction"" /a:d ^|find ""test""') do echo The real path of ""%a"" is %b")
Do While p.Status = 0
WScript.Sleep 100
Loop
WScript.Echo p.StdOut.ReadAll
我不知道用纯 VBScript 获取此信息的方法,但您可以 shell 到 fsutil
提取此信息:
foldername = "C:\the Junction\test"
Set sh = CreateObject("WScript.Shell")
Set fsutil = sh.Exec("fsutil reparsepoint query """ & foldername & """")
Do While fsutil.Status = 0
WScript.Sleep 100
Loop
If fsutil.ExitCode <> 0 Then
WScript.Echo "An error occurred (" & fsutil.ExitCode & ")."
WScript.Quit fsutil.ExitCode
End If
Set re = New RegExp
re.Pattern = "Substitute Name:\s+(.*)"
For Each m In re.Execute(fsutil.StdOut.ReadAll)
targetPath = m.SubMatches(0)
Next
WScript.Echo targetPath
如果要从路径中排除前导 \??\
,请将模式更改为 Substitute Name:\s+\\?\?\(.*)
。
我有一个文件夹C:\the Junction\test
,其实是一个路口,真实路径(目标)是D:\the real\path\to\the folder
.
如何在 VBScript 中找到真正的目标路径?
试试这个代码:
Set p = CreateObject("WScript.Shell").Exec("cmd /c @echo off & for /f ""tokens=5,6"" %a IN ('dir ""c:\the junction"" /a:d ^|find ""test""') do echo The real path of ""%a"" is %b")
Do While p.Status = 0
WScript.Sleep 100
Loop
WScript.Echo p.StdOut.ReadAll
我不知道用纯 VBScript 获取此信息的方法,但您可以 shell 到 fsutil
提取此信息:
foldername = "C:\the Junction\test"
Set sh = CreateObject("WScript.Shell")
Set fsutil = sh.Exec("fsutil reparsepoint query """ & foldername & """")
Do While fsutil.Status = 0
WScript.Sleep 100
Loop
If fsutil.ExitCode <> 0 Then
WScript.Echo "An error occurred (" & fsutil.ExitCode & ")."
WScript.Quit fsutil.ExitCode
End If
Set re = New RegExp
re.Pattern = "Substitute Name:\s+(.*)"
For Each m In re.Execute(fsutil.StdOut.ReadAll)
targetPath = m.SubMatches(0)
Next
WScript.Echo targetPath
如果要从路径中排除前导 \??\
,请将模式更改为 Substitute Name:\s+\\?\?\(.*)
。