Purge files in destination which don't exist in the source
This commit is contained in:
@@ -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.")
|
||||
# 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.")
|
||||
Reference in New Issue
Block a user