-
-
Save ryanbekabe/c2778e907f7d4d3de53d71217591eebe to your computer and use it in GitHub Desktop.
PYTHON: unzip all files in a directory
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os, zipfile | |
for filename in os.listdir("."): | |
if filename.endswith(".zip"): | |
print filename | |
name = os.path.splitext(os.path.basename(filename))[0] | |
if not os.path.isdir(name): | |
try: | |
zip = zipfile.ZipFile(filename) | |
os.mkdir(name) | |
zip.extractall(path=name) | |
except zipfile.BadZipfile, e: | |
print "BAD ZIP: "+filename | |
try: | |
os.remove(filename) | |
except OSError as e: # this would be "except OSError, e:" before Python 2.6 | |
if e.errno != errno.ENOENT: # errno.ENOENT = no such file or directory | |
raise # re-raise exception if a different error occured |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment