Tim said:
Shortcuts to other (original) files are easy to create.
But how do I find out all the Shortcuts with a target which
does not exist any more (or which are moved in the meanwhile)?
Hi,
You can use the VBScript code below to do this. Put the script
in a file with the file extension .vbs
'--------------------8<----------------------
'
' Script that locates scortcuts with missing target files
'
' It supports the following operations:
'
' 1)
' Dragging of one or more link file(s) to the script icon
'
' 2)
' Dragging of *one* folder to the script icon
' or add the folder to the command line.
' All link files in this folder and subfolders will then be enumerated
'
'
' Author: Torgeir Bakken
' Date: 2006-03-01
'
' File where result (if any found) will be written to
sResultFile = "c:\MissingTargets.txt"
Const OpenAsASCII = 0
Const OverwriteIfExist = -1
Set oArgs = WScript.Arguments
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oShell = CreateObject("WScript.Shell")
sTitle = "Chck for missing shortcut target"
bFilesOnly = True ' init value
If oArgs.Count = 0 Then
MsgBox "Error: You need to supply shortcut file(s) or path as input " _
& "parameter!", _
vbCritical + vbSystemModal, sTitle
Wscript.Quit
Elseif oArgs.Count = 1 And oFSO.FolderExists(oArgs(0)) Then
sSource = oArgs(0)
bFilesOnly = False
End If
Dim sMissingLinkTargetPaths
sMissingLinkTargetPaths = ""
If bFilesOnly Then
For i = 0 to oArgs.Count - 1
sSource = oArgs(i)
If LCase(oFSO.GetExtensionName(sSource)) = "lnk" Then
Set oShellLink = oShell.CreateShortcut(sSource)
sLinkTargetPath = oShellLink.TargetPath
If Not oFSO.FileExists(sLinkTargetPath) Then
sMissingLinkTargetPaths = sMissingLinkTargetPaths _
& vbCrLf & sSource
End If
End If
Next
Else
Call EnumFolders(sSource)
End If
If sMissingLinkTargetPaths <> "" Then
Set fOutFile = oFSO.CreateTextFile _
(sResultFile, OverwriteIfExist, OpenAsASCII)
fOutFile.WriteLine sMissingLinkTargetPaths
fOutFile.Close
oShell.Run "Notepad.exe """ & sResultFile & """" , 1, False
Else
MsgBox "No shortcuts with missing target file found!", _
vbInformation + vbSystemModal, sTitle
End If
Sub EnumFolders(sPath)
Dim oFolder, oFiles, oFile, oFldr
Set oFolder = oFSO.GetFolder(sPath)
Set oFiles = oFolder.Files
For Each oFile In oFiles
If LCase(oFSO.GetExtensionName(oFile)) = "lnk" Then
Set oShellLink = oShell.CreateShortcut(oFile.Path)
sLinkTargetPath = oShellLink.TargetPath
If Not oFSO.FileExists(sLinkTargetPath) Then
sMissingLinkTargetPaths = sMissingLinkTargetPaths _
& vbCrLf & oFile.Path
End If
End If
Next
For Each oFldr In oFolder.SubFolders
EnumFolders oFldr.Path
Next
End Sub
'--------------------8<----------------------