Skip files which haven't changed

This commit is contained in:
2025-01-03 18:56:41 -05:00
parent 0fbbb03ec7
commit 3bf486d477

View File

@@ -1,5 +1,4 @@
import sys, os, shutil import sys, os, shutil, filecmp, configparser
import configparser
config = configparser.ConfigParser() config = configparser.ConfigParser()
@@ -95,6 +94,7 @@ fileExtensionsToCopy = (
totalFiles = 0 totalFiles = 0
totalFilesCopied = 0 totalFilesCopied = 0
totalFilesAlreadyValid = 0
for folder in foldersToCopy: for folder in foldersToCopy:
for root, dirs, files in os.walk(sourceDir + "\\" + folder): for root, dirs, files in os.walk(sourceDir + "\\" + folder):
for file in files: for file in files:
@@ -104,9 +104,15 @@ for folder in foldersToCopy:
relname = pathname.replace(sourceDir, "") relname = pathname.replace(sourceDir, "")
destpath = copyToDir + relname destpath = copyToDir + relname
if os.path.isfile(pathname): if os.path.isfile(pathname):
if os.path.isfile(destpath) and filecmp.cmp(pathname, destpath, shallow=True):
print("Skipping " + pathname)
totalFilesAlreadyValid = totalFilesAlreadyValid + 1
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(relname)
print(str(totalFiles) + " total files. " + str(totalFilesCopied) + " copied.") print(str(totalFiles) + " total files. " + str(totalFilesCopied) + " copied. " + str(totalFilesAlreadyValid) + " were not copied because they were identical.")