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