obsidian/resourceraw.py

146 lines
5.3 KiB
Python
Raw Normal View History

2025-03-26 00:02:56 +08:00
import os
import csv
from re import S
import shutil
currentPath = os.getcwd().replace('\\','/') # 获取当前路径
rawPath = "" # 资源raw路径
# 测试写入fbx
def WriteCsv():
r1 = [1,2,3]
r2 = [4,5,6]
csvfile = open("./resource.csv","w",encoding='utf-8')
writer = csv.writer(csvfile,lineterminator='\n')
writer.writerow(["文件名","绝对路径","备注"])
writer.writerows([r1,r2])
csvfile.close()
# 获取Raw绝对路径
def GetRawPath():
PathList = currentPath.split("/")
for i in range(len(PathList)):
global rawPath
if(PathList[i] != "ResourcesRaw"):
rawPath = rawPath + PathList[i] + "/"
else:
rawPath = rawPath + PathList[i] + "/"
break
# 第一次筛选,筛选出公共的表情动作模型资源
def FirseListFile(dirPath):
restcsvFile = open("./rest.csv","w",encoding='utf-8') # 剩余文件列表
restWriter = csv.writer(restcsvFile,lineterminator='\n')
restWriter.writerow(["文件名","绝对路径","所属"])
Firstcsvfile = open("./first.csv","w",encoding='utf-8') # 第一次修改的文件列表
writer = csv.writer(Firstcsvfile,lineterminator='\n')
writer.writerow(["文件名","绝对路径","所属","编号"])
for root, dirs, files in os.walk(dirPath):
# fileName.append()z
# 循环遍历列表files【所有文件】仅得到不包含路径的文件名
for fileObj in files:
global rawPath
case = fileObj.casefold()
name = str(fileObj)
belong = ""
index = ""
if((".fbx" in case)):
if((not ".meta" in case) and ("prop" in case) and (not "ing" in case) and (not "lob" in case)):
nameList = name.split("@")
if(len(nameList) > 1):
frontNameList = nameList[0].split("&")
if(len(frontNameList) > 1):
belong = frontNameList[1]
behindNameList = nameList[1].split("_")
if(len(behindNameList) > 1):
index = behindNameList[0]
belongNameList = belong.split("_")
if(index.isdigit() and len(index) == 8 and len(belongNameList) == 2):
# 空列表写入遍历的文件名称,并用目录路径拼接文件名称
path = os.path.join(root, fileObj).replace('\\','/')
dir = rawPath + "Common/" + belong + "/Props/" + index + "/Models/"
if(not os.path.exists(dir)):
os.makedirs(dir)
shutil.move(path,dir+"/"+ fileObj)
shutil.move(path + ".meta",dir+"/"+ fileObj + ".meta")
writer.writerow([fileObj,path,belong,index])
else:
path = os.path.join(root, fileObj).replace('\\','/')
frontName = name.split("@")
frontNameList = frontName[0].split("&")
behindList = frontNameList[1].split("_")
dir = rawPath + "Common/" + belong + "/Props/Common/Models/"
if(not os.path.exists(dir)):
os.makedirs(dir)
shutil.move(path,dir+"/"+ fileObj)
shutil.move(path + ".meta",dir+"/"+ fileObj + ".meta")
restWriter.writerow([fileObj,path,behindList[0]+"_"+behindList[1]])
Firstcsvfile.close()
restcsvFile.close()
def SecondListFile(dirPath):
alreadyList = []
with open("./1.csv",encoding='utf-8-sig') as f:
index = 0
for row in csv.reader(f,skipinitialspace=True):
if(index > 0):
# print(row[0])
alreadyList.append(row[0])
index = index + 1
f.close()
with open("./2.csv",encoding='utf-8-sig') as f:
index = 0
for row in csv.reader(f,skipinitialspace=True):
if(index > 0):
# print(row[0])
alreadyList.append(row[0])
index = index + 1
f.close()
Firstcsvfile = open("./first.csv","w",encoding='utf-8') # 第一次修改的文件列表
writer = csv.writer(Firstcsvfile,lineterminator='\n')
writer.writerow(["文件名","绝对路径"])
for root, dirs, files in os.walk(dirPath):
# 循环遍历列表files【所有文件】仅得到不包含路径的文件名
for fileObj in files:
case = fileObj.casefold()
name = str(fileObj)
if(('.fbx' in case) and (not '.meta' in case) and (not name in alreadyList)):
# 空列表写入遍历的文件名称,并用目录路径拼接文件名称
path = os.path.join(root, fileObj).replace('\\','/')
writer.writerow([fileObj,path])
Firstcsvfile.close()
GetRawPath()
# FirseListFile(currentPath)
SecondListFile(currentPath)