那些年我们用过的Python代码

根据正则表达式选择性解压文件

from zipfile import ZipFile
import re

def is_match(expression, filename):
    pattern = re.compile(expression)
    match = pattern.match(filename)
    return match

def decompression(zipFileName, expression, filePath):
    zip_file = ZipFile(zipFileName)
    file_list = zip_file.namelist()
    for name in file_list:
        if is_match(expression, name):
            print(name)
            zip_file.extract(name, filePath)

if __name__ == '__main__':
    decompression(r"E:\Temp\20130816.zip", ".*DST.*", r"E:\Temp\22")

 

posted @ 2013-09-04 17:13  会长  阅读(428)  评论(0编辑  收藏  举报