import zipfile
f = zipfile.ZipFile('d:\\testzip.zip','w',zipfile.ZIP_DEFLATED)
f.write('poem.txt')
f.write('Chapter 3.docx')
f.close()
f = zipfile.ZipFile('d:\\testzip.zip','r',zipfile.ZIP_DEFLATED)
f.extract('poem.txt','d:\\')
print "namelist is :", f.namelist()
print "filename is :", f.filename
print "The zip file contains files below:"
for item in f.namelist():
print item,len(item)
read the content of the file in the zip : f.read(item),
for info in f.infolist():
print info.filename, info.file_size,info.date_time,info.compress_size
f.close()
#######zip files under specific dolder
## using glob.glob to get the path list under specific folder
import zipfile
import glob, os
file = zipfile.ZipFile("d:\\test.zip", "w")
for name in glob.glob("D:\\learned SQLs in progress\\*\\*"): ##zip all the files under this foler
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
print glob.glob("D:\\learned SQLs in progress\\*\\*")
file.close()
file = zipfile.ZipFile("d:\\test.zip", "r")
for info in file.infolist():
print info.filename, info.date_time, info.file_size, info.compress_size
file.close()
############how to get all the foldes and files list under one specific folder????????
f = zipfile.ZipFile('d:\\testzip.zip','w',zipfile.ZIP_DEFLATED)
f.write('poem.txt')
f.write('Chapter 3.docx')
f.close()
f = zipfile.ZipFile('d:\\testzip.zip','r',zipfile.ZIP_DEFLATED)
f.extract('poem.txt','d:\\')
print "namelist is :", f.namelist()
print "filename is :", f.filename
print "The zip file contains files below:"
for item in f.namelist():
print item,len(item)
read the content of the file in the zip : f.read(item),
for info in f.infolist():
print info.filename, info.file_size,info.date_time,info.compress_size
f.close()
#######zip files under specific dolder
## using glob.glob to get the path list under specific folder
import zipfile
import glob, os
file = zipfile.ZipFile("d:\\test.zip", "w")
for name in glob.glob("D:\\learned SQLs in progress\\*\\*"): ##zip all the files under this foler
file.write(name, os.path.basename(name), zipfile.ZIP_DEFLATED)
print glob.glob("D:\\learned SQLs in progress\\*\\*")
file.close()
file = zipfile.ZipFile("d:\\test.zip", "r")
for info in file.infolist():
print info.filename, info.date_time, info.file_size, info.compress_size
file.close()
############how to get all the foldes and files list under one specific folder????????