使用 Python,获取 zip 存档中的文件名

发布于 2024-09-18 14:59:42 字数 220 浏览 1 评论 0原文

我在网站上有几个非常大的 zip 文件可供下载。我正在使用 Flask 微框架(基于 Werkzeug),它使用 Python。

有没有一种方法可以向网页上的某人显示 zip 文件的内容(即文件和文件夹名称),而无需实际下载它?就像在服务器端进行锻炼一样。

假设我自己不知道 zip 档案中有什么。

我很抱歉这篇文章不包含代码。

谢谢你的帮助。

I have several very large zip files available to download on a website. I am using Flask microframework (based on Werkzeug) which uses Python.

Is there a way to show the contents of a zip file (i.e. file and folder names) - to someone on a webpage - without actually downloading it? As in doing the working out server side.

Assume that I do not know what are in the zip archives myself.

I apoligize that this post does not include code.

Thank you for helping.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

初熏 2024-09-25 14:59:42

当然,看看 zipfile.ZipFile.namelist()< /代码>。正如您所期望的,用法非常简单:您只需为所需的文件创建一个 ZipFile 对象,然后 namelist() 会为您提供 ZipFile 的路径列表存储在存档中的文件。

with ZipFile('foo.zip', 'r') as f:
    names = f.namelist()
print names
# ['file1', 'folder1/file2', ...]

Sure, have a look at zipfile.ZipFile.namelist(). Usage is pretty simple, as you'd expect: you just create a ZipFile object for the file you want, and then namelist() gives you a list of the paths of files stored in the archive.

with ZipFile('foo.zip', 'r') as f:
    names = f.namelist()
print names
# ['file1', 'folder1/file2', ...]
横笛休吹塞上声 2024-09-25 14:59:42

http://docs.python.org/library/zipfile.html

具体来说,尝试使用 ZipFile.namelist() 方法。

http://docs.python.org/library/zipfile.html

Specifically, try using the ZipFile.namelist() method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文