Skip to content

Instantly share code, notes, and snippets.

@githubutilities
Last active November 29, 2018 15:10
Show Gist options
  • Save githubutilities/a19ad1c69f6447bb86f8 to your computer and use it in GitHub Desktop.
Save githubutilities/a19ad1c69f6447bb86f8 to your computer and use it in GitHub Desktop.
Shell and python script to verify zip file integrity
#! /usr/bin/python
import os
import zipfile
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith('.zip'):
try:
zfile = zipfile.ZipFile(file)
except zipfile.BadZipfile as ex:
print "%s no a zip file" % file
continue
ret = zfile.testzip()
if ret is not None:
print "%s bad zip file, error: %s" % file, ret
else:
print "%s OK" % file
#! /bin/bash
for f in *.zip
do
zip --test $f 1>/dev/null && echo $f 'OK'
if (($? > 0)); then
# use double quote for $f to function
printf '%s \n' "$f bad file" >&2
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment