# -*- coding: utf-8 -*-
import os
import shutil
import sys
def UnZipFile(inputPath, outPath):
_unZipPath = os.getcwd() + "\\7-Zip\\7z.exe "#原来输出成果物的进行了压缩,输出到指定的build里,所以我们要利用7z.exe来解压缩。需要调用此程序
_param = " x " + inputPath + " -o"
_param = _param + outPath
_cmd = _unZipPath + _param
print _cmd
os.system(_cmd)
def GetbiggestFolder(inputPath): #获取文件夹操作
_maxPath = ""
_maxNum = 0
for folder in os.listdir(inputPath):
_inputFolderPath = os.path.join(inputPath, folder)
if os.path.isdir(_inputFolderPath):
if str(folder).isdigit():
if int(folder) > _maxNum :
_maxNum = int(folder)
_maxPath = _inputFolderPath
return _maxPath
def copyFile(_oldPath, _newPath):
if os.path.exists(_newPath) is not True:
os.makedirs(_newPath)
if os.path.isdir(_newPath):
shutil.copy(_oldPath, _newPath)
def Usage(s = ""):
print "Usage: unzip.py [source folder] [target folder]"
if s:
print s
sys.exit(1)
if __name__ == "__main__":
"""while True:
g_InputPath = raw_input("Please input source folder path:")
if g_InputPath.rfind('\\') != -1:
break
while True:
g_OutputPath = raw_input("Please input target folder path:")
if g_OutputPath.rfind('\\') != -1:
break
"""
argv = sys.argv
i = 1
iLen = len(argv)
if len(argv) != 3:
_errorInfor = "There should be 2 parameters, but you input " + str(iLen -1)
Usage(_errorInfor)
g_InputPath = argv[1]
g_OutputPath = argv[2]
_maxPath = GetbiggestFolder(g_InputPath)
print _maxPath
for _file in os.listdir(_maxPath):
_inputFilePath = os.path.join(_maxPath, _file)
if os.path.isfile(_inputFilePath):
if _file.find('.7z') != -1 or _file.find('.rar') != -1 or _file.find('.zip') != -1:
print _inputFilePath
UnZipFile(_inputFilePath, g_OutputPath)
copyFile(_inputFilePath, g_OutputPath)