#!/usr/bin/python # -*- coding: UTF-8 -*- import sys import os, os.path import subprocess import shutil def LzmaUncompressFile(filePath, filePathNew): if not os.path.exists(filePath): return if not os.path.isfile(filePath): return cmd = 'LzmaUncompress.exe {0} {1}'.format(filePath, filePathNew) # print(cmd) subprocess.call(cmd) # dir 目录下存放的是未解密的*.7z文件 # dirNew 目录是解密后归档的文件所在的目录 def LzmaUncompressDir(dir, dirNew): if not os.path.exists(dir): return if not os.path.isdir(dir): return fileList = os.listdir(dir) fileCount = len(fileList) fileIndex = 0; for file in fileList: if file != ".gitignore": dirdst = dirNew arr = file.split("_") if len(arr) >= 5: messageKey = arr[3] dateTime = arr[4][:8] dirdst = os.path.join(dirdst, messageKey) dirdst = os.path.join(dirdst, dateTime) if not os.path.exists(dirdst): os.makedirs(dirdst) filePath = os.path.join(dir, file) filePathNew = os.path.join(dirdst, file) filePathNew += ".log" LzmaUncompressFile(filePath, filePathNew) os.remove(filePath) fileIndex += 1 print("{} / {}".format(fileIndex, fileCount)) if __name__ == '__main__': args_num = len(sys.argv) if args_num >= 2: dirOld = sys.argv[1] dirNew = sys.argv[2] LzmaUncompressDir(dirOld, dirNew)