Python: Quick recipe for reading a rar file

First of all, download the rarfile.py from http://grue.l-t.ee/~marko/src/rarfile/README.html. This python program contains all the classes and methods to handle a .rar file. Download it and save it in the LIB folder.

# check if it is rarfile where f is a file
if tarfile.is_rarfile(f):
# if it is a rar file then open the file for reading
z = rarfile.RarFile(f, r)
# get all the filenames in the .rar package
for filename in z.namelist():
print filename
In this way you can manipulate a rar file. In the same way you can manipulate a tar file or a zip file by using the zipfile class or tar file class in python. But in tarfile class we have the getnames() class object we should be using instead of nameslist() class object.

In

Leave a Reply

Your email address will not be published. Required fields are marked *