How do I know an item is a directory while looping over zipfile in Python?
Starting with Python 3.6 there is a ZipInfo.is_dir()
method.
with zipfile.ZipFile(zip_file) as archive:
for file in archive.namelist():
file_info = archive.getinfo(file)
if file_info.is_dir():
# do something
See the Python 3.6 docs for details.
Probably this is the right way:
is_dir = lambda zipinfo: zipinfo.filename.endswith('/')