Reputation: 3651
How do I traverse the contents of a zip file in python without having to extract them?
If extracting is the only way, is it efficient if I create a unique temp folder and extract them there then traverse and remove the temp folder afterwards?
Upvotes: 1
Views: 1451
Reputation: 400174
Use the namelist()
method of the ZipFile
class to get a list of all of the filenames in the archive without having to extract them. For example:
import zipfile
myzip = zipfile.ZipFile('myzip.zip', 'r')
filenames = myzip.namelist()
# Do something with filenames
Upvotes: 3