Doing something like this:
from zipfile import ZipFile
#open zip file
zipfile = ZipFile('Photo.zip')
#iterate zip contents
for zipinfo in zipfile.filelist:
#do something
filepath, filename = path.split(zipinfo.filename)
How do I know if zipinfo
is a file or a directory?
Thanks for your support.
isdir() or a file with TarInfo. isfile() . Similarly you can determine whether a file is a zip file using zipfile. is_zipfile() .
The ZIP file format is a common archive and compression standard. This module provides tools to create, read, write, append, and list a ZIP file. Any advanced use of this module will require an understanding of the format, as defined in PKZIP Application Note.
Probably this is the right way:
is_dir = lambda zipinfo: zipinfo.filename.endswith('/')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With