My friend gave me 10,000+ ROM's for Sega, SNES, NES, and GBA. They where all individually zipped. I go fed up trying to unzip them one by one, and decided to write a script to do it for me. It unzipped about 5,000 in under a minute. Python's zipfile module is nice, but it sometimes wont open some zip files. It throws an error saying something like "Corrupt Zip File", but seems to unzip fine with 7Zip. I use 7Zip for all my compression needs now a days, but this script was a learning experience, so I though I would pass it along.
Mass Unzipper
import zipfile, os
print """=-=-=-=-=-=-=--=MASS_ZIP_EXTRACTION=-=-=-=-=-=-=--=
=-=-=-=-=-=-=-=-By: Tech B. =-=-=-=-=-=-=-=-=-=-="""
print """
"""
d = raw_input("""Path to Directory containing the Zip's to be extracted
example: C:\\Users\\TechB\\Desktop\\Zips
:""")
zList = os.listdir(d)
badList = []
gnt = 0
bnt = 0
allz = 0
for z in zList:
try:
di = d
di += '\\' + z
if zipfile.is_zipfile(di) == True:
x = zipfile.ZipFile(di)
x.extractall(raw_input("""Path to where you want the zips to be extracted to
example: C:\\Users\\owner\\Extraction_Folder
:"""))
gnt += 1
allz += 1
print "extracted: ", z, gnt
else:
bnt += 1
allz += 1
badList.append(z)
print "failed: ", z, bnt
except:
allz += 1
badList.append(z)
print 'Error: ', z
print "=-=-=-=-=-=-==-=-=-=-=-=-="
print "Total files: %d" % allz
print "=-=-=-=-=-=-=-==-=-=-=-=-="
print "Failed files:"
for i in badList:
print i
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.