I'm trying to extract a specific file from a zip archive using python.
In this case, extract an apk's icon from the apk itself.
I am currently using
ziphandle = open(tDir + mainapk[0],'rb') #`pwd`/temp/x.apk
zip = zipfile.ZipFile(ziphandle)
zip.extract(icon[1], tDir) # extract /res/drawable/icon.png from apk to `pwd`/temp/...
which does work, in my script directory it's creating temp/res/drawable/icon.png
which is temp plus the same path as the file is inside the apk.
What I actually want is to end up with temp/icon.png.
Is there any way of doing this directly with a zip command, or do I need to extract, then move the file, then remove the directories manually?
You can use zipfile.ZipFile.read:
Or use zipfile.ZipFile.open: