How to find all shortcuts with missing target ?

  • Thread starter Thread starter Tim Tuples
  • Start date Start date
T

Tim Tuples

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)?

Tim
 
There are a vast number of 'cleanup' programs that will do this for you. Norton WinDoctor (part of SystemWorks) is but one example.

A better question is why you are concerned about these broken links, since they cause absolutely no problem for your computer and take up a truly negligable amount of space.

Another question is why you felt the need to crosspost to so many newsgroups, particularly for a trivial question.

Steven
 
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<----------------------
 
As to why : simply perhaps because some people do not like to have useless
things in their PC / office / ....

"M and D" <[email protected]> a écrit dans le message de (e-mail address removed)...
There are a vast number of 'cleanup' programs that will do this for you.
Norton WinDoctor (part of SystemWorks) is but one example.

A better question is why you are concerned about these broken links, since
they cause absolutely no problem for your computer and take up a truly
negligable amount of space.

Another question is why you felt the need to crosspost to so many
newsgroups, particularly for a trivial question.

Steven
 
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)?

Tim
Tim;

Shortcuts to non-existant targets are called orphans. There are a lot
of utilities available to take care of this. One that was just
mentioned on alt.comp.freeware is:

http://www.digiarch.org/orphansremover.html

Wrt finding/updating links to those targets which have moved, I dunno.

hth,
-Craig
 
Back
Top