问题描述
我正在尝试编写一个非常简单的脚本,用于计算给定 ZIP 文件所具有的条目/文件数,以进行一些统计.
I'm attempting to write a very simple script that counts the number of entries/files a given ZIP file has, for some statistics.
我正在使用 zipfile
库,但我遇到了这个库似乎不支持 .zipx 格式的问题.
I'm using the zipfile
library, and I'm running into this problem where the library appears not to support .zipx format.
bash-3.1$ python zipcount.py t.zipx
Traceback (most recent call last):
File "zipcount.py", line 10, in <module>
zipCount(file)
File "zipcount.py", line 5, in zipCount
with ZipFile(file, "r") as zf:
File "c:\Python34\lib\zipfile.py", line 937, in __init__
self._RealGetContents()
File "c:\Python34\lib\zipfile.py", line 978, in _RealGetContents
raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file
谷歌搜索显示 zipx
格式与 zip
不同,所以也许我不应该期望它会起作用.进一步的谷歌搜索虽然未能找到一个实际上可以处理zipx
的库.搜索堆栈溢出也没有找到太多.
Googling for help reveals that the zipx
format is not the same as zip
, and so maybe I shouldn't be expecting this to work. Further googling though fails to bring up a library that actually can deal with zipx
. Searching stack overflow didn't find much either.
我不可能是唯一想在 python 中操作 zipx 文件的人,对吧?有什么建议吗?
I can't possibly be the only person who wants to manipulate zipx files in python, right? Any suggestions?
推荐答案
chilkat 可能适用于此.它不是免费图书馆,但有 30 天的试用期.这是 http://www.example-code.com/python/ppmd_compress_file 中的示例.asp:
import sys
import chilkat
compress = chilkat.CkCompression()
# Any string argument automatically begins a 30-day trial.
success = compress.UnlockComponent("30-day trial")
if (success != True):
print "Compression component unlock failed"
sys.exit()
compress.put_Algorithm("ppmd")
# Decompress back to the original:
success = compress.DecompressFile("t.zipx", "t")
if (success != True):
print compress.lastErrorText()
sys.exit()
print "Success!"
API 文档:http://www.chilkatsoft.com/refdoc/pythonCkCompressionRef.html
这篇关于使用 Python 访问 .zipx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!