如何在Python中仅列出zip存档中的文件夹? [英] How can i list only the folders in zip archive in Python?

查看:78
本文介绍了如何在Python中仅列出zip存档中的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何仅列出zip存档中的文件夹?
这将列出存档中的每个跟踪文件和文件:

How can i list only the folders from a zip archive? This will list every folfder and file from the archive:

import zipfile
file = zipfile.ZipFile("samples/sample.zip", "r")
for name in file.namelist():
    print name

谢谢。

推荐答案

一种方法可能是:

>>> [x for x in file.namelist() if x.endswith('/')]
<<< ['folder/', 'folder2/']

这篇关于如何在Python中仅列出zip存档中的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆