如何获得交叉点的目标路径?

时间:2015-06-03 15:52:56

标签: vbscript junction

我有一个文件夹C:\the Junction\test,实际上是一个联结,实际路径(目标)是D:\the real\path\to\the folder

如何在VBScript中找到真正的目标路径?

2 个答案:

答案 0 :(得分:2)

我不知道使用普通VBScript获取此信息的方法,但您可以向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+\\\?\?\\(.*),请将模式更改为\??\

答案 1 :(得分:1)

试试这段代码:

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