renamer.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import os
  2. import shutil
  3. currdir = os.getcwd()
  4. path = currdir
  5. prefixlist = ["icon-","inhand-left-","inhand-right-","equipped-INNERCLOTHING-","equipped-FEET-","equipped-BACKPACK-","equipped-BELT-","equipped-EYES-","equipped-HAND-","equipped-HELMET-","equipped-MASK-","equipped-NECK-","equipped-OUTERCLOTHING-"]
  6. if (__name__ == "__main__"):
  7. print("Listing files...")
  8. with open("fulllist.txt","w") as writing: # this is where we will list all the orphaned files
  9. for root, dirs, files in os.walk(path+"\\sprites"): # checks all files and folders in the base folder
  10. for file in files:
  11. filesp = file.replace("\n","") # removes the paragraph at the end of the string
  12. if(file.endswith(".png") and filesp.find("exported") == -1):
  13. # if it has one of the extensions, split it so we get the filename without dirs
  14. filesp = str(root)+"\\"+str(file) # get the absolute directory
  15. _id = file.replace(".png","")
  16. equip = ""
  17. for prefix in prefixlist:
  18. if _id.find(prefix) != -1:
  19. _name,_id = _id.split(prefix)
  20. if prefix.find("equipped-"):
  21. equip = prefix
  22. writing.write(filesp+"||"+_id+"||"+equip+"\n") # return the last value of the splitted array and write to the file
  23. #all listed, now lets pair
  24. print("Finished listing the files.")
  25. print("Pairing by id...")
  26. if not os.path.isdir(currdir+"\\exported"):
  27. os.mkdir(currdir+"\\exported")
  28. with open("fulllist.txt", "r") as reading:
  29. for filepath in reading:
  30. filepath = filepath.replace("\n","") # remove the paragraph
  31. splitpath,splitid,splitprefix = filepath.split("||")
  32. print("Checking {}...".format(splitid))
  33. with open("fulllist.txt", "r") as reading2:
  34. for filepath2 in reading2:
  35. filepath2 = filepath2.replace("\n","") # remove the paragraph
  36. if not filepath2 == filepath:
  37. splitpath2,splitid2,splitprefix2 = filepath2.split("||")
  38. if splitid == splitid2 and not splitpath == splitpath2:
  39. print(" {} matches {}!".format(splitpath2,splitid))
  40. if not os.path.isdir(currdir+"\\exported\\"+splitid):
  41. os.mkdir(currdir+"\\exported\\"+splitid)
  42. shutil.copy(splitpath, currdir+"\\exported\\"+splitid)
  43. shutil.copy(splitpath2, currdir+"\\exported\\"+splitid)
  44. reading.close()