When you try to open a shortcut file (.lnk) that no longer works, Windows lets you know with a prompt that says: "This shortcut has been changed or moved, so this shortcut will no longer work properly." Is there a python code I can use to detect whether such a shortcut no longer works?
When I run the following code to retrieve the target path of a shortcut that no longer works, I don't get any type of error. The code still prints the path to the target file that doesn't exist anymore:
import win32com.client
shell = win32com.client.Dispatch('WScript.Shell')
shortcut = shell.CreateShortcut(shortcutpath_cur)
target = shortcut_cur.Targetpath
print(target)
Sometimes a shortcut no longer works even if the document it points to still exists. In that case, I couldn't use os.path.exists()
or os.path.isfile()
because they would return True
.