1. ZIP Compress, Decompress Library
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | import zipfile def checkZip(filename): return zipfile.is_zipfile(filename) class pyzip(): def __init__(self,filename,create=None): if create is None: if filename is not None and zipfile.is_zipfile(filename) == True: self.zf = zipfile.ZipFile(filename) else: self.zf = zipfile.ZipFile(filename, mode='w') def close(self): self.zf.close() def namelist(self): return self.zf.namelist() def infolist(self,filename): return self.zf.infolist() def extract(self,inname,outfile): data = self.zf.read(inname) binaryToFile(outfile,data) def add(self,filename): self.zf.write(filename) def dump(self): for info in self.zf.infolist(): print( "%20s: %s" % ('name', info.filename) ) print( "%20s: %s" % ('org_size', info.file_size) ) print( "%20s: %s" % ('cmp_size', info.compress_size) ) print( "%20s: %s" % ('modified', info.date_time) ) print( "Total: %d" % (len(self.zf.infolist()))) |
2. ZIP Library Test Example
1 2 3 4 5 6 7 | def zipTest(): z = pyzip('D:/Temp/a.zip') z.dump() z.extract('pyshell_demo.py','D:/Temp/pyshell_demo.py_zipout') z2 = pyzip('D:/Temp/b.zip', create=True) z2.add('D:/Temp/aa.py'); z2.close() |
댓글 없음:
댓글 쓰기