2 Upvotes

Extracting from a Zip File Using Python

Python
General Python

Code demonstrating how use the zipfile Python library to extract the contents of a zip file. In this example, all contents of the zip file are extracted to the current working directory.

import zipfile

#Extracts all contents of export.zip
zip_file = zipfile.ZipFile('export.zip')
zip_file.extractall()
zip_file.close()

#Extracts only the contents of data folder from export.zip
zip_file = zipfile.ZipFile('export.zip')
zip_file.extractall('data')
zip_file.close()

By GregHe1979 - Last Updated Sept. 8, 2021, 10:15 p.m.

Did you find this snippet useful?

Sign up to bookmark this in your snippet library

COMMENTS
RELATED SNIPPETS
Python For Else Loop
Python
General Python

Loop

2
Top Contributors
103
100