I have a series of text files in a folder that I want to zip. I compress the folder and produce a zip file.
When I programmtically call the zipfile I get an error: BadZipFile: File is not a zip file
.
I have been testing the zipped directory using this piece of code:
import zipfile
print (zipfile.is_zipfile("~/path/to/zipfile.zip") )
[output]:false
I have even tried programmtically creating a new zipped directory with this code and trying the above zipfile checker code, but also get False from this:
import os
import zipfile
def zipdir(path, ziph):
# ziph is zipfile handle
for root, dirs, files in os.walk(path):
for file in files:
ziph.write(os.path.join(root, file))
zipf = zipfile.ZipFile('Zipped_file.zip', 'w', zipfile.ZIP_DEFLATED)
zipdir('~/Desktop/cleaned_files_2', zipf)
zipf.close()
What am I doing wrong that I am not producing valid zipped directories?