码迷,mamicode.com
首页 > 编程语言 > 详细

Python实现 zip解压缩到指定目录

时间:2016-04-01 20:19:09      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:

 1 #!/bin/env python
 2 #-*- coding:utf-8 -*-
 3 import zipfile,os
 4 import platform,sys,os
 5 from zipfile import *
 6 import zipfile
 7 systty = platform.system()
 8 system1 = windows
 9 system2 = Linux
10 def unzip():
11     if systty.lower() == system1.lower():
12     # if systty.lower() == ‘windows‘:
13         flag = "\\"
14         source_zip="E:\\CGserve.zip"
15         target_dir="E:\\"
16         #print(systty,"这是一台windows机器!!!")
17         print(systty,"thisi is windows machine!!!")
18     elif system2.lower() == linux:
19         flag = "/"
20         source_zip="/home/CGserve.zip"
21         target_dir="/home/common/CGuardian"
22         print(systty,"thisi is linux machine!!!")
23     else:
24         print("not found....!")
25         sys.exit(1)
26     myzip = zipfile.ZipFile(source_zip)
27     myfilelist=myzip.namelist()
28     for name in myfilelist:
29         mylist = name.split(/)
30         mylist.pop()
31         tmp_dir = flag.join(mylist)
32         base_dir = "%s%s" % (target_dir,tmp_dir)
33         #print(base_dir)
34         if os.path.isdir(base_dir):
35             pass
36         else:
37             os.makedirs(base_dir)
38         f_handle = open(target_dir+name,"wb")
39         f_handle.write(myzip.read(name))
40     f_handle.close()
41 unzip()

 

Python实现 zip解压缩到指定目录

标签:

原文地址:http://www.cnblogs.com/nb-blog/p/5345915.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!