-
Notifications
You must be signed in to change notification settings - Fork 0
/
moveLods.py
75 lines (69 loc) · 2.21 KB
/
moveLods.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import os
import hashlib;
import sys;
import re
import time
import importlib
import shutil
importlib.reload(sys);
import warnings
import xml.etree.ElementTree as ET
warnings.filterwarnings("ignore")
def file_extension(path):
return os.path.splitext(path)[1]
def listFiles(dirPath):
fileList=[]
for root,dirs,files in os.walk(dirPath):
for fileObj in files:
fileList.append(os.path.join(root,fileObj))
return fileList
def listDirectFiles(dirPath):
fileList=[]
for root,dirs,files in os.walk(dirPath):
for fileObj in files:
if os.path.exists(os.path.join(dirPath,fileObj)):
fileList.append(os.path.join(root,fileObj))
return fileList
def GetFileNameAndExt(filename):
import os
(filepath,tempfilename) = os.path.split(filename);
(shotname,extension) = os.path.splitext(tempfilename);
return shotname
# sys.setdefaultencoding("utf-8");
def main(fileDir):
fileList = listDirectFiles(fileDir)
if not os.path.exists(os.path.join(fileDir, "lods")):
os.mkdir(os.path.join(fileDir, "lods"))
for fileObj in fileList:
if file_extension(fileObj) == '.model':
tree = ET.parse(fileObj)
#tree.write("%s2" % fileObj)
print(fileObj)
root = tree.getroot()
for child in root:
if child.text and "_lod" in child.text and "lods" not in child.text:
print(child.text)
child.text=os.path.join("%s/lods/" %os.path.split(child.text)[0],os.path.split(child.text)[1])
tree.write(fileObj)
if "lod" in fileObj:
shutil.move(fileObj, os.path.join(fileDir, "lods"))
#if file_extension(fileObj) == '.model':
#shutil.move("%s2" % fileObj, os.path.join(fileDir, "lods"))
if os.path.exists("./aircraft/"):
main("./aircraft/")
if os.path.exists("./catapult/"):
main("./catapult/")
if os.path.exists("./director/"):
main("./director/")
if os.path.exists("./finder/"):
main("./finder/")
if os.path.exists("./gun/"):
main("./gun/")
if os.path.exists("./misc/"):
main("./misc/")
if os.path.exists("./radar/"):
main("./radar/")
if os.path.exists("./projectile/"):
main("./projectile/")
if os.path.exists("./ship/"):
main("./ship/")