Fixed cleanup to delete empty folders, #491

This commit is contained in:
Rhet Turnbull
2021-07-06 21:57:43 -07:00
parent c23f3fc5e4
commit 1bf11b0414
2 changed files with 8 additions and 8 deletions

View File

@@ -1,3 +1,3 @@
""" version info """ """ version info """
__version__ = "0.42.59" __version__ = "0.42.60"

View File

@@ -3280,13 +3280,13 @@ def cleanup_files(dest_path, files_to_keep, fileutil):
# delete empty directories # delete empty directories
deleted_dirs = [] deleted_dirs = []
for p in pathlib.Path(dest_path).rglob("*"): # walk directory tree bottom up and verify contents are empty
path = str(p).lower() for dirpath, _, _ in os.walk(dest_path, topdown=False):
# if directory and directory is empty if not list(pathlib.Path(dirpath).glob("*")):
if p.is_dir() and not next(p.iterdir(), False): # directory and directory is empty
verbose_(f"Deleting empty directory {p}") verbose_(f"Deleting empty directory {dirpath}")
fileutil.rmdir(p) fileutil.rmdir(dirpath)
deleted_dirs.append(str(p)) deleted_dirs.append(str(dirpath))
return (deleted_files, deleted_dirs) return (deleted_files, deleted_dirs)