Purge files in destination which don't exist in the source
This commit is contained in:
@@ -74,6 +74,7 @@ fileExtensionsToCopy = (
|
|||||||
".pre",
|
".pre",
|
||||||
".ptc",
|
".ptc",
|
||||||
".ragdoll",
|
".ragdoll",
|
||||||
|
".rdb",
|
||||||
".sig",
|
".sig",
|
||||||
".siga",
|
".siga",
|
||||||
".smap",
|
".smap",
|
||||||
@@ -91,6 +92,7 @@ fileExtensionsToCopy = (
|
|||||||
".xob"
|
".xob"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Copy files to destination but compare to make sure not wasting time copying
|
||||||
totalFiles = 0
|
totalFiles = 0
|
||||||
totalFilesCopied = 0
|
totalFilesCopied = 0
|
||||||
totalFilesAlreadyValid = 0
|
totalFilesAlreadyValid = 0
|
||||||
@@ -105,13 +107,27 @@ for folder in foldersToCopy:
|
|||||||
if os.path.isfile(pathname):
|
if os.path.isfile(pathname):
|
||||||
|
|
||||||
if os.path.isfile(destpath) and filecmp.cmp(pathname, destpath, shallow=True):
|
if os.path.isfile(destpath) and filecmp.cmp(pathname, destpath, shallow=True):
|
||||||
print("Skipping " + pathname)
|
#print("Skipping " + pathname)
|
||||||
totalFilesAlreadyValid = totalFilesAlreadyValid + 1
|
totalFilesAlreadyValid = totalFilesAlreadyValid + 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
os.makedirs(os.path.dirname(destpath), exist_ok=True)
|
os.makedirs(os.path.dirname(destpath), exist_ok=True)
|
||||||
shutil.copy2(pathname, destpath)
|
shutil.copy2(pathname, destpath)
|
||||||
totalFilesCopied = totalFilesCopied + 1
|
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