How to Extract a Zip File With Python

Written by langstond
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Extract a Zip File With Python
A zip file keeps data nicely and neatly compressed. (zip image by Ivan Hafizov from

Python is an open license programming language available in Windows, Linux and Mac, plus Java .Net virtual machines. Python features three versions, with each newer version adding more compatibility and features. Zip files are compressed files that save space on a hard drive by grouping the files together to lower the overall size. Python can create, manage and extract zip files.

Skill level:


  1. 1

    Open the Python compiler. Make sure all the lines are empty of text by highlighting and deleting any text.

  2. 2

    Copy and paste the following into the compiler:

    import zipfile

    fullpathToZip = "c:\temp\"

    destination Path = "c:\temp\Extracted"

    source Zip = zipfile.ZipFile(fullpathToZip, 'r')

    for name in sourceZip.namelist():

    if name.find('.txt')!= -1

    sourceZip.extract(name, destination Path)


  3. 3

    Change the second line of the text command to represent the zipfile that you wish to extract. Change the third line of the command to represent the destination where you'd like the files to be extracted.

  4. 4

    Change the file association in the sixth command line to the type of file that you wish to extract from the zip file. Run the script and watch as the files are extracted and presented to you.

Don't Miss

  • All types
  • Articles
  • Slideshows
  • Videos
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the site, you consent to the use of cookies. For more information, please see our Cookie policy.