diff --git a/menuinst/platforms/win.py b/menuinst/platforms/win.py index 97ea56d7..e001e7d9 100644 --- a/menuinst/platforms/win.py +++ b/menuinst/platforms/win.py @@ -37,13 +37,15 @@ def create(self) -> Tuple[os.PathLike]: def remove(self) -> Tuple[os.PathLike]: # Only remove if the Start Menu directory is empty in case applications share a folder. - try: - menu_location = Path(self.start_menu_location) - if menu_location.exists(): + menu_location = Path(self.start_menu_location) + if menu_location.exists(): + try: + # Check directory contents. If empty, it will raise StopIteration + # and only in that case we delete the directory. next(menu_location.iterdir()) - except StopIteration: - log.debug("Removing %s", self.start_menu_location) - shutil.rmtree(self.start_menu_location, ignore_errors=True) + except StopIteration: + log.debug("Removing %s", self.start_menu_location) + shutil.rmtree(self.start_menu_location, ignore_errors=True) return (self.start_menu_location,) @property