Python's ZipFile module

Source: Internet
Author: User
Tags zipinfo

ZipFile. ZipFile (FILE,MODE,COMPRESS_TYPE,ALLOWZIP64) #创建一个ZipFile对象
File:zip file name
Mode: ' R ' reads the existing zip file, ' W ' new or overwrites the existing zip file, ' a ' appended to the existing ZIP document
Compress_type:zipfile. Zip_stored is not compressed by default, ZipFile. zip_deflated compression
ALLOWZIP64: Default False, zip exceeds 2G set to True

Zipfile.getinfo (name) #获取zip文档内指定文件信息, returns ZipFile. Zipinfo Object

Zipfile.infolist () #获取zip文档内所有文件信息, returns ZipFile. Zipinfo List

Zipfile.namelist () #获取zip文档内所有文件的名称列表

Zipfile.extract (MEMBER,PATH,PWD) #把zip文档内指定文件解压到指定目录
Member: The file name or Zipinfo object to unzip
Path: Specify unzip directory (default current directory)
PWD: Extracting passwords

Zipfile.extractall (PATH,MEMBERS,PWD) #解压zip文档到指定目录
Path: Extract destination directory, default current directory
Members: Set the list of file names, default all
PWD: Extracting passwords

Zipfile.printdir () #打印zip文档信息

Zipfile.setpassword (PWD) #设置zip文档密码
PWD: Extracting passwords

Zipfile.read (NAME,PWD) #获取zip文档内指定文件的二进制
Name:zip file specified in document
PWD: Extracting passwords

Zipfile.write (Filename,arcname,compress_type) #添加指定文件到zip文档中
FileName: File path
Arcname: Saved Name
Compress_type:zipfile. Zip_stored is not compressed by default, ZipFile. zip_deflated compression

Zipfile.writestr (zinfo_or_arcname,bytes) #直接写二进制到压缩文档

Zipinfo.filename #文件名称
Zipinfo.date_time #最后修改时间, returns (years, months, days, hours, minutes, seconds) of the tuple
Zipinfo.compress_type #压缩类型
Zipinfo.comment #文档说明
ZIPINFO.EXTR #扩展项数据
Zipinfo.create_system #创建该文档的系统
Zipinfo.create_version #创建该文档的PKZIP版本
Zipinfo.extract_version #解压该文档所需的PKZIP版本
Zipinfo.reserved #预留字段
Zipinfo.flag_bits #zip标志位
Zipinfo.volume #文件头的卷标
Zipinfo.internal_attr #内部属性
Zipinfo.external_attr #外部属性
Zipinfo.header_offset #文件头偏移位
ZIPINFO.CRC #未压缩文件的CRC-32
Zipinfo.compress_size #压缩后大小
Zipinfo.file_size #未压缩大小

Python's ZipFile module

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.