LearnPython - Zip格式文件的解压缩

 1 import zipfile
 2 import os
 3 
 4 
 5 def unzip(zip_name, target_dir):
 6     files = zipfile.ZipFile(zip_name)
 7     for zip_file in files.namelist():
 8         files.extract(zip_file, target_dir)
 9 
10 
11 def main():
12     zip_name = r'./image.zip'   # 被测试的Zip文件放在与py文件相同的目录下
13     target_dir = r'./'
14     if os.path.exists(target_dir):
15         unzip(zip_name, target_dir)
16     else:
17         os.makedirs(target_dir)
18         unzip(zip_name, target_dir)
19 
20 
21 if __name__ == '__main__':
22     main()

猜你喜欢

转载自www.cnblogs.com/zlian2016/p/9953917.html
今日推荐