123456789101112131415161718192021222324252627282930313233343536373839404142 |
- # -*- coding: utf-8
- import sys
- import os
- import re
- import json
- #root_dir_path = "../release/bytedancegame"
- root_dir_path = sys.argv[1]
- extern_name_list = [".json", ".ExportJson", ".ls", ".lh", ".lmat"]
- def removeBlankChar(filepath):
- f1 = open(filepath, "rb")
- content1 = f1.read()
- f1.close()
- content2 = re.sub("[*\\t\\n\\r]", "", content1) #"[\\s*\\t\\n\\r]"或"\s" (空格不去掉,以防命名中有空格)
- f2 = open(filepath, "wb")
- f2.write(content2)
- f2.close()
- print "remove blank char complete. file: %s" % filepath
- # end of removeBlankChar
- def removeBlankCharOfDir(dirpath):
- filename_list = os.listdir(dirpath)
- for filename in filename_list:
- filepath = dirpath + "/" + filename
- if os.path.isdir(filepath):
- removeBlankCharOfDir(filepath)
- else:
- for extern_name in extern_name_list:
- if filepath[-len(extern_name):] == extern_name:
- removeBlankChar(filepath)
- break
- # end of removeBlankCharOfDir
- removeBlankCharOfDir(root_dir_path)
- print "minifyJson complete"
- #raw_input("\n\ndone! ....")
- #sys.exit(0)
|