#python 替换Resourceraw文件目录 ``` py from curses.ascii import isdigit from ntpath import join import os import csv import re from re import S import shutil from xpinyin import Pinyin import unicodedata currentPath = os.getcwd().replace('\\','/') # 获取当前路径 CurrentPathList = currentPath.split("/") backUpCurrentPath = "" for i in range(len(CurrentPathList)-3): backUpCurrentPath = backUpCurrentPath + CurrentPathList[i] + "/" p = Pinyin() rawPath = "" # 资源raw路径 inGameEmotionPath = "" # 局内表情动作路径 outGameEmotionPath = "" # 局外表情动作路径 currentPaths = [] inGameBelongList = [] outGameBelongList = [] commonGameBelongList = [] # 获取Raw绝对路径 def GetRawPath(): PathList = currentPath.split("/") global rawPath for i in range(len(PathList)): if(PathList[i] != "CommonRegion"): rawPath = rawPath + PathList[i] + "/" else: rawPath = rawPath + PathList[i] + "/" break simple_punctuation = '[,!]' #中文字符检测 def ChangeName(name): # name = unicodedata.normalize('NFKC',) name = re.sub(simple_punctuation,'',p.get_pinyin(name)) index = name.find('-') if (index != -1): front = name[:index] back = name[(index+1):] name = (front+back).replace("-","_") return name def GetBelongList(): global inGameEmotionPath global outGameEmotionPath global currentPaths inGameEmotionPath = rawPath + "InGame/Skins/Emotions/" outGameEmotionPath = rawPath + "OutsideGame/Skins/Emotions/" SkinsinGameEmotionPath = rawPath + "Skins/InGameEmotion/" currentPaths = [inGameEmotionPath,outGameEmotionPath,SkinsinGameEmotionPath] inGameFileList = os.listdir(inGameEmotionPath) for line in inGameFileList: if(not ".meta" in line): inGameBelongList.append(line) outGameFileList = os.listdir(outGameEmotionPath) for line in outGameFileList: if(not ".meta" in line): outGameBelongList.append(line) def ChangeResourceRaw(dirPaths): Othercsvfile = open("./ResourceRawChange.csv","w",encoding='utf-8') writer = csv.writer(Othercsvfile,lineterminator='\n') writer.writerow(["文件名","原路径","目标路径","类型","编号","所属","局内外","是否为Prop"]) alreadyList = [] # 适配早期fbx文件筛选 global rawPath global backUpCurrentPath global p # # 旧版遍历fbx 1 for dirPath in dirPaths: for root, dirs, files in os.walk(dirPath): # 循环遍历列表:files【所有文件】,仅得到不包含路径的文件名 for fileObj in files: case = fileObj.casefold() name = str(fileObj) belong = "" index = "" # 模型fbx 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("_") belongnameList = belong.split("_") # print("belongNameList:"+str(belong)) for i in range(len(belongnameList)): if (belongnameList[i].isdigit() and i >=1): belong = belongnameList[i-1] + "_" + belongnameList[i] break if(inGameBelongList.__contains__(belong)): isProp = False if('prop' in case): isProp = True if(index.isdigit() and len(index) == 8 and len(belongNameList) == 2 and isProp): # 空列表写入遍历的文件名称,并用目录路径拼接文件名称 path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") if('@' in case): dir = (rawPath + "Common/Skins/Emotions/" + belong + "/Props/" + index + "/Animations/") else: dir = (rawPath + "Common/Skins/Emotions/" + belong + "/Props/" + index + "/Models/") dir = dir.replace(backUpCurrentPath,"") targetPath = ChangeName(dir + name) writer.writerow([fileObj,path,targetPath,"fbx",index,belong,"Common",isProp]) alreadyList.append(fileObj) else: path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") frontName = name.split("@") frontNameList = frontName[0].split("&") behindList = frontNameList[1].split("_") # dir = (rawPath + "Common/Skins/Emotions/" + belong + "/Animations/") # dir = dir.replace(backUpCurrentPath,"") if(behindList[1].isdigit()): writer.writerow([ChangeName(name),path,"","fbx","",behindList[0]+"_"+behindList[1],"Common",isProp]) alreadyList.append(fileObj) # # # 旧版遍历fbx 2 InOrOut = "" Belong = "" Index = "" for dirPath in dirPaths: for root, dirs, files in os.walk(dirPath): # 循环遍历列表:files【所有文件】,仅得到不包含路径的文件名 for fileObj in files: case = fileObj.casefold() name = str(fileObj) if(('.fbx' in case) and ("prop" in case) and (not '.meta' in case) and (not name in alreadyList) and (('&ing' in case) or ('&lob' in case) or ('ingame' in case) or ('lobby' in case))): # 空列表写入遍历的文件名称,并用目录路径拼接文件名称 path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") front = name.split("@") # 局内外标识 if(('&ing' in case) or ('ingame' in case)): InOrOut = "InGame" elif(('&lob' in case) or ('lobby' in case)): InOrOut = "OutsideGame" # 所属 belongNameList = front[0].split("&") if(len(belongNameList) > 1): nameList = belongNameList[1].split("_") if(len(nameList) >= 3): Belong = nameList[1] + "_" + nameList[2] else: Belong = belongNameList[1] if(inGameBelongList.__contains__(Belong)): # 编号 if(len(front) > 1): behind = front[1].split("_") if(behind[0].isdigit()): Index = behind[0] dir = rawPath + InOrOut + "/Skins/Emotions/" + Belong + "/Props/" + Index + "/Animations/" dir = dir.replace(backUpCurrentPath,"") if(path != dir + fileObj): targetPath = ChangeName(dir + fileObj) writer.writerow([fileObj,path,targetPath,"fbx",Index,Belong,InOrOut,True]) alreadyList.append(fileObj) # # # 旧版遍历fbx 3 for dirPath in dirPaths: for root,dirs,files in os.walk(dirPath): 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('\\','/') path = path.replace(backUpCurrentPath,"") if((('@' in case) and (not 'Animations' in path)) or ((not '@' in case) and (not 'Models' in path)) or ('mdl&sorb' in path)): # 特殊处理 mdl&sorb.fbx notleft = name.split(".")[0] nameList = notleft.split("@") isHasNumber = False isHasBeLong = False for i in range(len(nameList)): secNameList = nameList[i].split("_") for secName in secNameList: if(secName.isdigit() and len(secName) >= 8): isHasNumber = True for gameBelong in inGameBelongList: smallGameBelong = gameBelong.casefold() if(smallGameBelong in case): isProp = False if('prop' in case): isProp = True writer.writerow([ChangeName(name),path,"","fbx",secName,gameBelong,"",isProp]) isHasBeLong = True break if(isHasBeLong == False): isProp = False if('prop' in case): isProp = True writer.writerow([ChangeName(name),path,"","fbx",secName,"","",isProp]) if(isHasNumber == False): isProp = False if('prop' in case): isProp = True writer.writerow([ChangeName(name),path,"","fbx","","","",isProp]) # 新版 遍历材质 for dirPath in dirPaths: for root, dirs, files in os.walk(dirPath): # 循环遍历列表:files【所有文件】,仅得到不包含路径的文件名 for fileObj in files: case = fileObj.casefold() name = str(fileObj) # 遍历材质 if(('.mat' in case) and (not '.meta' in case)): path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") isRight = False for inGameBelong in inGameBelongList: belong = "/"+inGameBelong+"/" if(belong in path): isRight = True break if((not isRight) or (not "Materials" in path)): isProp = False if('prop' in case): isProp = True HasIndex = False Index = "" InOut = "" if('lob' in case): InOut = "OutsideGame" elif('ing' in case): InOut = "InGame" MineGameBelong = "" for gameBeLong in inGameBelongList: smallGameBelong = gameBeLong.casefold() if(smallGameBelong in case): MineGameBelong = gameBeLong break nameList = name.split("@") for OneName in nameList: TwoNameList = OneName.split("&") for TwoName in TwoNameList: ThreeNameList = TwoName.split('_') for ThreeName in ThreeNameList: ThreeName = ThreeName.replace(".mat","") if(ThreeName.isdigit() and len(ThreeName) == 8): Index = ThreeName HasIndex = True break if(HasIndex == True): break if(HasIndex == True): break writer.writerow([ChangeName(name),path,"","mat",Index,MineGameBelong,InOut,isProp]) # 新版 遍历tga文件 for root,dirs,files in os.walk(dirPaths[2]): for fileObj in files: case = fileObj.casefold() name = str(fileObj) if(('.tga' in case) and (not '.meta' in case)): path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") isProp = False HasIndex = False Index = "" InOut = "" MineGameBelong = "" if('lob' in case): InOut = "OutsideGame" elif('ing' in case): InOut = "InGame" if('prop' in case): isProp = True for gameBeLong in inGameBelongList: smallGameBelong = gameBeLong.casefold() if(smallGameBelong in case): MineGameBelong = gameBeLong break nameList = name.split("@") for OneName in nameList: TwoNameList = OneName.split("&") for TwoName in TwoNameList: ThreeNameList = TwoName.split('_') for ThreeName in ThreeNameList: ThreeName = ThreeName.replace(".tga","") if(ThreeName.isdigit() and len(ThreeName) == 8): Index = ThreeName HasIndex = True break if(HasIndex == True): break if(HasIndex == True): break writer.writerow([ChangeName(name),path,"","tga",Index,MineGameBelong,InOut,isProp]) # 新版 遍历controller文件 for root,dirs,files in os.walk(dirPaths[2]): for fileObj in files: case = fileObj.casefold() name = str(fileObj) if(('.controller' in case or '.overridecontroller' in case) and (not '.meta' in case)): path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") isProp = False HasIndex = False Index = "" InOut = "" MineGameBelong = "" if('lob' in case): InOut = "OutsideGame" elif('ing' in case): InOut = "InGame" if('prop' in case): isProp = True for gameBeLong in inGameBelongList: smallGameBelong = gameBeLong.casefold() if(smallGameBelong in case): MineGameBelong = gameBeLong break nameList = name.split("@") for OneName in nameList: TwoNameList = OneName.split("&") for TwoName in TwoNameList: ThreeNameList = TwoName.split('_') for ThreeName in ThreeNameList: ThreeName = ThreeName.replace(".controller","") if(ThreeName.isdigit() and len(ThreeName) == 8): Index = ThreeName HasIndex = True break if(HasIndex == True): break if(HasIndex == True): break writer.writerow([ChangeName(name),path,"","controller",Index,MineGameBelong,InOut,isProp]) # 新版 遍历动画 for root,dirs,files in os.walk(dirPaths[2]): for fileObj in files: case = fileObj.casefold() name = str(fileObj) if(('.anim' in case) and (not '.meta' in case)): path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") isProp = False HasIndex = False Index = "" InOut = "" MineGameBelong = "" if('lob' in case): InOut = "OutsideGame" elif('ing' in case): InOut = "InGame" if('prop' in case): isProp = True for gameBeLong in inGameBelongList: smallGameBelong = gameBeLong.casefold() if(smallGameBelong in case): MineGameBelong = gameBeLong break nameList = name.split("@") for OneName in nameList: TwoNameList = OneName.split("&") for TwoName in TwoNameList: ThreeNameList = TwoName.split('_') for ThreeName in ThreeNameList: ThreeName = ThreeName.replace(".anim","") if(ThreeName.isdigit() and len(ThreeName) == 8): Index = ThreeName HasIndex = True break if(HasIndex == True): break if(HasIndex == True): break writer.writerow([ChangeName(name),path,"","anim",Index,MineGameBelong,InOut,isProp]) # 新版 遍历图片 for root,dirs,files in os.walk(dirPaths[2]): for fileObj in files: case = fileObj.casefold() name = str(fileObj) if(('.png' in case or '.jpeg' in case) and (not '.meta' in case) and (not 'spr&动作_战斗内转盘_Custom.png' in name) and (not 'tex&动作_战斗内转盘_选中_Custom.png' in name)): path = os.path.join(root, fileObj).replace('\\','/') path = path.replace(backUpCurrentPath,"") isProp = False HasIndex = False Index = "" InOut = "" MineGameBelong = "" if('lob' in case): InOut = "OutsideGame" elif('ing' in case): InOut = "InGame" if('prop' in case): isProp = True for gameBeLong in inGameBelongList: smallGameBelong = gameBeLong.casefold() if(smallGameBelong in case): MineGameBelong = gameBeLong break nameList = name.split("@") for OneName in nameList: TwoNameList = OneName.split("&") for TwoName in TwoNameList: ThreeNameList = TwoName.split('_') for ThreeName in ThreeNameList: ThreeName = ThreeName.replace(".png","") if(ThreeName.isdigit() and len(ThreeName) == 8): Index = ThreeName HasIndex = True break if(HasIndex == True): break if(HasIndex == True): break writer.writerow([ChangeName(name),path,"","png",Index,MineGameBelong,InOut,isProp]) # 新版 遍历预制体 # for dirPath in dirPaths: # for root, dirs, files in os.walk(dirPath): # # 循环遍历列表:files【所有文件】,仅得到不包含路径的文件名 # for fileObj in files: # case = fileObj.casefold() # # 遍历预制体 # if(('.prefab' in case) and (not '.meta' in case)): # path = os.path.join(root, fileObj).replace('\\','/') # path = path.replace(backUpCurrentPath,"") # writer.writerow([fileObj,path,"","prefab","","",""]) Othercsvfile.close() def RestResourceRaw(): global currentPaths with open("./ResourceRawChange.csv",encoding='utf-8-sig') as f: index = 0 restIndex = 0 alreadyList = [] checkRepeatNameList = [] for row in csv.reader(f,skipinitialspace=True): if (index >0): if(row[0].split('.')[0] in checkRepeatNameList): print("存在重名:"+row[0].split('.')[0]) return checkRepeatNameList.append(row[0].split('.')[0]) alreadyList.append(row[0]) # row[1] = r"C:/Users/liaoyourong\Downloads/code/gieCLONE/hide/" + row[1] # row[2] = r"C:/Users/liaoyourong\Downloads/code/gieCLONE/hide/" + row[2] # rowList = row[2].split("/") # dir = row[2].replace(rowList[len(rowList)-1],"") # if(not os.path.exists(dir)): # os.makedirs(dir) # shutil.move(row[1],row[2]) index = index + 1 for root, dirs, files in os.walk(currentPaths[2]): # 循环遍历列表:files【所有文件】,仅得到不包含路径的文件名 for fileObj in files: name = ChangeName(str(fileObj)) if(not name in alreadyList and not '.meta' in name and not 'spr&dong_zuo___zhan_dou_nei_zhuan_pan__Custom.png' in name and not 'tex&dong_zuo___zhan_dou_nei_zhuan_pan___xuan_zhong__Custom.png' in name): print("剩余需要手动修改的:"+name) restIndex = restIndex + 1 f.close() input("resourceraw表情动作目录修改完毕 剩余" + str(restIndex) +"个需要手动修改目录") # 创建 GetRawPath() GetBelongList() ChangeResourceRaw(currentPaths) RestResourceRaw() ```