解压缩文件导致" BadZipFile"

时间:2017-06-27 11:50:05

标签: python zip unzip compression

我知道有类似的问题,但它们都没有为我的问题提供解决方案。我使用以下代码:

import os, glob
import zipfile

root = 'E:\\xx\\fashion\\*'
directory = 'E:\\xx\\fashion\\'
extension = ".zip"

date_file_list = []
for folder in glob.glob(root):
    if folder.endswith(extension): # check for ".zip" extension
        print(folder)
        zipfile.ZipFile(os.path.join(directory, folder)).extractall(os.path.join(directory, os.path.splitext(folder)[0]))
        os.remove(folder) # delete zipped file_name

我收到以下错误:

Traceback (most recent call last):
  File "C:/Users/xx/unzip.py", line 12, in <module>
    zipfile.ZipFile(os.path.join(directory, folder)).extractall(os.path.join(directory, os.path.splitext(folder)[0]))
  File "C:\Users\xx\AppData\Local\Programs\Python\Python35\lib\zipfile.py", line 1026, in __init__
    self._RealGetContents()
  File "C:\Users\xx\AppData\Local\Programs\Python\Python35\lib\zipfile.py", line 1094, in _RealGetContents
    raise BadZipFile("File is not a zip file")
zipfile.BadZipFile: File is not a zip file

有些文件是在winzip中压缩的,其中一些文件是7zip。但是有太多的文件要解压缩。 有人知道为什么会出现这个错误吗?

0 个答案:

没有答案