difenduandada
2024-12-31 34abe6963b344c882358274957f4b992456fee40
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
# 开始压缩数据
import os
import os.path
import sys
import zlib
 
def compress_md5files(srcPath):
    files = os.listdir(srcPath)
 
    for f in files:
        path = os.path.join(srcPath, f)
        postfix = os.path.splitext(path)[1].lower()
        if (os.path.isdir(path)):
            compress_md5files(path)
        else:
            if os.path.isfile(path) and (postfix == ".m5m" or postfix == ".m5a"):
                compress_md5file(path)
 
def compress_md5file(filePath):
    f = open(filePath, "r")
    rawData = f.read()
    f.close()
 
    cData = zlib.compress(rawData, zlib.Z_BEST_COMPRESSION)
 
    f = open(filePath + "c", "w")
    f.write(cData)
    f.close()
 
    print("压缩文件完毕:{0}".format(filePath))
 
 
 
if __name__ == "__main__":
    workingDir = "./"
 
    if 2 == len(sys.argv):
        srcPath = os.path.join(workingDir, sys.argv[1])
        if os.path.isdir(srcPath):
            compress_md5files(srcPath)
        else:
            compress_md5file(srcPath)
        exit(0)