Getting files in a subdirectory in a zip

E

Echo

What would the best way to get a list of files in a subdirectory in a zip?

The only thing I can come up with is to extract the zip into a temp
directory and then just grab the list of files in the subdirectory
that I need. This way seems very messy to me and I was wondering if
there are any better ways.
 
S

Scott David Daniels

Echo said:
What would the best way to get a list of files in a subdirectory in a zip?

The only thing I can come up with is to extract the zip into a temp
directory and then just grab the list of files in the subdirectory
that I need. This way seems very messy to me and I was wondering if
there are any better ways.

import zipfile
z = zipfile.ZipFile('block.zip')
names = [name[7:] for name in z.namelist()
if name.startswith('others/')]

--Scott David Daniels
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top