p_minifyJson.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # -*- coding: utf-8
  2. import os
  3. import re
  4. import json
  5. import sys
  6. #root_dir_path = "../release/bytedancegame"
  7. root_dir_path = sys.argv[1]
  8. extern_name_list = [".json", ".ExportJson", ".ls", ".lh", ".lmat"]
  9. def removeBlankChar(filepath):
  10. f1 = open(filepath, "rb")
  11. content1 = f1.read()
  12. f1.close()
  13. content2 = re.sub("[*\\t\\n\\r]", "", content1) #"[\\s*\\t\\n\\r]"或"\s" (空格不去掉,以防命名中有空格)
  14. f2 = open(filepath, "wb")
  15. f2.write(content2)
  16. f2.close()
  17. print "remove blank char complete. file: %s" % filepath
  18. # end of removeBlankChar
  19. def removeBlankCharOfDir(dirpath):
  20. filename_list = os.listdir(dirpath)
  21. for filename in filename_list:
  22. filepath = dirpath + "/" + filename
  23. if os.path.isdir(filepath):
  24. removeBlankCharOfDir(filepath)
  25. else:
  26. for extern_name in extern_name_list:
  27. if filepath[-len(extern_name):] == extern_name:
  28. removeBlankChar(filepath)
  29. break
  30. # end of removeBlankCharOfDir
  31. removeBlankCharOfDir(root_dir_path)
  32. raw_input("\n\ndone! ....")