以下 DOS 命令创建一个连接点(称为Source
),指向一个Destination
不再存在的文件夹(称为 ):
mkdir Destination
mklink /J Source Destination
rd Destination
我目前正在使用以下 VBScript 来验证连接点的目的地是否存在:
' FileSystemObject is used for multiple things, so defined globally
Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
Function Valid_Junction(folderName)
Valid_Junction = True
On Error Resume Next
Dim count : count = fso.GetFolder(folderName).Files.Count
' An error will be thrown if the destination doesn't exist
If Err.Number <> 0 Then Valid_Junction = False
On Error Goto 0
End Function
在上面的示例中,调用Valid_Junction("Source")
正确返回False
,因为Destination
不再存在。
有没有更简单、更清洁或更有效的方法来做到这一点?