Python comes with a zipfile module for reading and writing zip files.
def zip_dir (dirname,zipfilename): filelist = [] if Os.path.isfile (dirname): filelist.append (dirname) else: for root, dirs, files in Os.walk (dirname): For name in Files: filelist.append (Os.path.join (Root , name)) ZF = ZipFile. ZipFile (Zipfilename, "w", ZipFile. zip_stored,allowzip64=true) for tar in filelist: arcname = Tar[len (dirname):] #print arcname Zf.write (Tar,arcname)
ZF = ZipFile. ZipFile (Zipfilename, "w", ZipFile. Zip_stored,allowzip64=true)
The above function has four functions: The zip file contains the name of the path, "W"/"R" means write or read, ZipFile. Zip_stored represents the storage format (and can also be zipfile.zlib.DEFLATED for a compressed format), allowzip64=true This parameter is used when working with large files, and defaults to false. If not set to True, the zip file size require ZIP64 extensions is prompted when processing large files.
Python zipfile module ZIP64