The following DOS commands create a junction (called Source
) pointing to a folder (called Destination
) which no longer exists:
mkdir Destination
mklink /J Source Destination
rd Destination
I'm currently using the following VBScript to verify that the destination of a junction point exists:
' 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
In the example above, calling Valid_Junction("Source")
correctly returns False
because Destination
no longer exists.
Is there an easier, cleaner or more efficient way of doing this?