112 lines
2.4 KiB
Python
112 lines
2.4 KiB
Python
|
|
import sys, os, shutil
|
||
|
|
import configparser
|
||
|
|
|
||
|
|
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",
|
||
|
|
".rdb",
|
||
|
|
".sig",
|
||
|
|
".siga",
|
||
|
|
".smap",
|
||
|
|
".st",
|
||
|
|
".stars",
|
||
|
|
".styles",
|
||
|
|
".terr",
|
||
|
|
".topo",
|
||
|
|
".ttf",
|
||
|
|
".ttile",
|
||
|
|
".txa",
|
||
|
|
".txo",
|
||
|
|
".vhcsurf",
|
||
|
|
".wav",
|
||
|
|
".xob"
|
||
|
|
)
|
||
|
|
|
||
|
|
totalFiles = 0
|
||
|
|
totalFilesCopied = 0
|
||
|
|
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):
|
||
|
|
os.makedirs(os.path.dirname(destpath), exist_ok=True)
|
||
|
|
shutil.copy2(pathname, destpath)
|
||
|
|
totalFilesCopied = totalFilesCopied + 1
|
||
|
|
print(relname)
|
||
|
|
|
||
|
|
print(str(totalFiles) + " total files. " + str(totalFilesCopied) + " copied.")
|