-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunzip-all.py
22 lines (19 loc) · 845 Bytes
/
unzip-all.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/python
import os, zipfile
#unzips all the zip folders down 1 level from the root.
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:
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