I can to unzip a file if file is a .zip and unrar file if my file type is .rar.
How i can do this work with python 2.7?
28
votes
5 Answers
31
votes
18
votes
11
votes
5
votes
After some deep diving, here are my findings:
- RAR is not an free open format and is owned by RARLabs. You must install their DLL or exe first to work with RAR. Some programs like 7zip might already include this with them.
patoolis application that provides uniform command line as wrapper to other external compression applications. Natively, it can only deal with TAR, ZIP, BZIP2 and GZIP without needing external support.pyunpackis Python library that can only deal with zip natively but provides interface topatool.
With this in mind, following things worked for me:
- Make sure 7zip is installed
pip install patool pyunpack
Then to use it,
import pyunpack
pyunpack.Archive(archive_file).extractall(extract_dir)