Unzip and Unrar to extract zipped files with Python and 7zip

How to unzip for free and in a very fast and easy way everything using the free tool 7zip 7-Zip and, of course, Python.

Go to this link to download 7zip and then install the two modules for python

  • patool
  • pyunpack

using, as usual, the beloved pip, going into the cmd (windows key + r and then write cmd, or go in the address bar of a folder and type cmd).

Then, in the same way, install pyunpack

Look at the video for a live explanation, but to extract the files from a rar file, remember that you have to install – with pip – patool and pyunpack, as I showed you right now, and then write this code and save it in a file (ex.: unzip.py), in the directory where the rar file is:

from pyunpack import Archive
Archive("file.rar").extractall(".")

After you saved the file, run it. You can go in the address bar of the folder where the files are and type cmd and then type in the cmd:

If you use the Mac, you should write python3 unzip.py. On windows it should work also py unzip.py.

Video for 7zip and Python to unzip rar or zip files

In the video below you will have all the details you need to do it correctly.

Utilities

Published by pythonprogramming

Started with basic on the spectrum, loved javascript in the 90ies and python in the 2000, now I am back with python, still making some javascript stuff when needed.