Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can unrar a file with python

How can I extract a .zip or .rar file using Python?

like image 271
Vahid Kharazi Avatar asked Jul 12 '13 12:07

Vahid Kharazi


People also ask

Can 7zip Unrar files?

7zip is so easy to use that you can use it to extract RAR files without even opening the software. All you have to do is right-click the RAR file you want to open, hover over the 7zip menu, and click one of the “extract” options, depending on where you want to extract the files.


2 Answers

Late, but I wasn't satisfied with any of the answers.

pip install patool import patoolib patoolib.extract_archive("foo_bar.rar", outdir="path here") 

Works on Windows and linux without any other libraries needed.

like image 106
Amir Avatar answered Sep 18 '22 13:09

Amir


Try the pyunpack package:

from pyunpack import Archive Archive('a.zip').extractall('/path/to') 
like image 32
Irakli Darbuashvili Avatar answered Sep 16 '22 13:09

Irakli Darbuashvili