Does anyone here know how to use the UnRAR2 module?
http://code.google.com/p/py-unrar2/downloads/list
I can't for the life of me I can't figure out how get it to do the same thing that zipfile does in a project I am working on. I want it to look for all files of a specific file type, print their name, and extract them to a specific directory. And do this for 4 different file types.
Here is the working code using zipfile:
def unzip():
try:
os.chdir(fileDir)
zip = zipfile.ZipFile(filename, "r")
print "\n---------------------------"
print "Installing..."
for name in zip.namelist():
if name.find(".package") != -1:
print "Found %s. Extracting to \Packages." % name
zip.extract(name, modDir + "\Packages")
elif name.find(".dbc") != -1:
print "Found %s. Extracting to \DCCache." % name
zip.extract(name, modDir + "\DCCache")
else:
print "No valid files found."
Now here is the test code I came up with when reading the module docs. I didn't really understand it.
def unrar():
try:
os.chdir(fileDir)
archive = UnRAR2.RarFile(filename)
print "\n---------------------------"
print "Installing..."
for fileInArchive in archive.infoiter():
os.path.split(fileInArchive.filename)[1]
if fileInArchive.filename == "*.txt":
print "That is a text file."
Of course, it doesn't work. Does anyone know how to make UnRAR2 do this? Or is there something better to use when working with .rar files?