From 2c9d8068ca3e7f442428d18935a1aa0d6b14a270 Mon Sep 17 00:00:00 2001 From: Adam Date: Sat, 4 Jan 2025 17:32:10 -0500 Subject: [PATCH] Purge files in destination which don't exist in the source --- Garbage Cleaner/garbageCleaner.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/Garbage Cleaner/garbageCleaner.py b/Garbage Cleaner/garbageCleaner.py index 1d24929..04a9a32 100644 --- a/Garbage Cleaner/garbageCleaner.py +++ b/Garbage Cleaner/garbageCleaner.py @@ -74,6 +74,7 @@ fileExtensionsToCopy = ( ".pre", ".ptc", ".ragdoll", + ".rdb", ".sig", ".siga", ".smap", @@ -91,6 +92,7 @@ fileExtensionsToCopy = ( ".xob" ) +# Copy files to destination but compare to make sure not wasting time copying totalFiles = 0 totalFilesCopied = 0 totalFilesAlreadyValid = 0 @@ -105,13 +107,27 @@ for folder in foldersToCopy: if os.path.isfile(pathname): if os.path.isfile(destpath) and filecmp.cmp(pathname, destpath, shallow=True): - print("Skipping " + pathname) + #print("Skipping " + pathname) totalFilesAlreadyValid = totalFilesAlreadyValid + 1 continue os.makedirs(os.path.dirname(destpath), exist_ok=True) shutil.copy2(pathname, destpath) totalFilesCopied = totalFilesCopied + 1 - print(relname) + print("Copying " + relname) -print(str(totalFiles) + " total files. " + str(totalFilesCopied) + " copied. " + str(totalFilesAlreadyValid) + " were not copied because they were identical.") \ No newline at end of file +# purge files in destination which do not exist in source +totalFilesPurged = 0 +for folder in foldersToCopy: + for root, dirs, files in os.walk(copyToDir + "\\" + folder): + for file in files: + pathname = root + "\\" + file + relname = pathname.replace(copyToDir, "") + sourcepath = sourceDir + relname + + if not os.path.isfile(sourcepath): + totalFilesPurged = totalFilesPurged + 1 + os.remove(pathname) + print("Deleting " + relname + " from destination because it doesn't exist in the source!") + +print(str(totalFiles) + " total files. " + str(totalFilesCopied) + " copied. " + str(totalFilesAlreadyValid) + " were not copied because they are identical. " + str(totalFilesPurged) + " files were purged from destination.") \ No newline at end of file