From 3d61b3b1ec5798eaac154de6343f8ff8b952383b Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Thu, 20 Aug 2020 11:27:58 -0700 Subject: [PATCH] Don't delete lnks that have empty string path. --- prune_shortcuts.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/prune_shortcuts.py b/prune_shortcuts.py index d81eb33..36571a0 100644 --- a/prune_shortcuts.py +++ b/prune_shortcuts.py @@ -14,6 +14,17 @@ from voussoirkit import pathclass def prune_shortcuts(autoyes=False): lnks = pathclass.Path('.').glob('*.lnk') stale = [lnk for lnk in lnks if not os.path.exists(winshell.Shortcut(lnk.absolute_path).path)] + stale = [] + for lnk in lnks: + shortcut = winshell.Shortcut(lnk.absolute_path) + # There are some special shortcuts that do not have a path, but instead + # trigger some action based on a CLSID that Explorer understands. + # I can't find this information in the winshell.Shortcut object, so for + # now let's at least not delete these files. + if shortcut.path == '': + continue + if not os.path.exists(shortcut.path): + stale.append(lnk) if not stale: return