Skip to content

Instantly share code, notes, and snippets.

@osvalr
Created September 1, 2017 02:40
Show Gist options
  • Save osvalr/d850df821e60dca608f0bb3da1188dff to your computer and use it in GitHub Desktop.
Save osvalr/d850df821e60dca608f0bb3da1188dff to your computer and use it in GitHub Desktop.
test if a zipfile is ok
from sys import argv
import zipfile
from zipfile import BadZipFile
message = "zip file okay"
try:
the_zip_file = zipfile.ZipFile(argv[1])
except BadZipFile:
message = "Bad file detected"
finally:
print(message)
@osvalr
Copy link
Author

osvalr commented Sep 1, 2017

test it with something like the following:

~/Downloads ❯ echo "1234567890" > my_file.zip
~/Downloads ❯ python badzipfile.py my_file.zip
Bad file detected
~/Downloads ❯

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment