2025-01-03 18:56:41 -05:00
import sys , os , shutil , filecmp , configparser
2025-01-03 15:06:53 -05:00
config = configparser . ConfigParser ( )
if os . path . isfile ( " config.ini " ) :
config . read ( " config.ini " )
else :
config [ " Settings " ] = {
" sourceDir " : " C: \\ somepath " ,
" copyToDir " : " C: \\ someotherpath " ,
" foldersToCopy " : " life1960,life1960_map,life1960_code "
}
with open ( " config.ini " , " w " ) as configfile :
config . write ( configfile )
print ( " Config created, please update it before running again. " )
sys . exit ( 0 )
sourceDir = config [ " Settings " ] [ " sourceDir " ]
copyToDir = config [ " Settings " ] [ " copyToDir " ]
if not os . path . exists ( sourceDir ) :
print ( " Invalid source directory " )
sys . exit ( 0 )
if not os . path . exists ( copyToDir ) :
print ( " Invalid destination directory " )
sys . exit ( 0 )
print ( " Copying files from: " + sourceDir )
foldersToCopy = tuple ( config [ " Settings " ] [ " foldersToCopy " ] . split ( " , " ) )
print ( foldersToCopy )
print ( " Copying files to: " + copyToDir )
fileExtensionsToCopy = (
" .acp " ,
" .adeb " ,
" .ae " ,
" .afm " ,
" .agf " ,
" .agr " ,
" .anm " ,
" .asc " ,
" .asi " ,
" .ast " ,
" .asy " ,
" .aw " ,
" .bt " ,
" .bterr " ,
" .bttile " ,
" .c " ,
" .conf " ,
" .ct " ,
# ".dds",
" .desc " ,
" .edds " ,
" .emat " ,
" .ent " ,
" .et " ,
# ".fbx",
" .fnt " ,
" .gamemat " ,
" .gproj " ,
" .imageset " ,
" .layer " ,
" .layout " ,
" .meta " ,
" .nmn " ,
" .pak " ,
" .pap " ,
" .physmat " ,
" .pre " ,
" .ptc " ,
" .ragdoll " ,
2025-01-04 17:32:10 -05:00
" .rdb " ,
2025-01-03 15:06:53 -05:00
" .sig " ,
" .siga " ,
" .smap " ,
" .st " ,
" .stars " ,
" .styles " ,
" .terr " ,
" .topo " ,
" .ttf " ,
" .ttile " ,
" .txa " ,
" .txo " ,
" .vhcsurf " ,
" .wav " ,
" .xob "
)
2025-01-04 17:32:10 -05:00
# Copy files to destination but compare to make sure not wasting time copying
2025-01-03 15:06:53 -05:00
totalFiles = 0
totalFilesCopied = 0
2025-01-03 18:56:41 -05:00
totalFilesAlreadyValid = 0
2025-01-03 15:06:53 -05:00
for folder in foldersToCopy :
for root , dirs , files in os . walk ( sourceDir + " \\ " + folder ) :
for file in files :
totalFiles = totalFiles + 1
if file . endswith ( fileExtensionsToCopy ) :
pathname = root + " \\ " + file
relname = pathname . replace ( sourceDir , " " )
destpath = copyToDir + relname
if os . path . isfile ( pathname ) :
2025-01-03 18:56:41 -05:00
if os . path . isfile ( destpath ) and filecmp . cmp ( pathname , destpath , shallow = True ) :
2025-01-04 17:32:10 -05:00
#print("Skipping " + pathname)
2025-01-03 18:56:41 -05:00
totalFilesAlreadyValid = totalFilesAlreadyValid + 1
continue
2025-01-03 15:06:53 -05:00
os . makedirs ( os . path . dirname ( destpath ) , exist_ok = True )
shutil . copy2 ( pathname , destpath )
totalFilesCopied = totalFilesCopied + 1
2025-01-04 17:32:10 -05:00
print ( " Copying " + relname )
2025-01-03 15:06:53 -05:00
2025-01-04 17:32:10 -05:00
# 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. " )