那些年我们用过的Python代码

时间:2021-03-11 12:35:08

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

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")