Mass Unzipper

Tech B 0 Tallied Votes 619 Views Share

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.

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
Stefano Mtangoo 455 Senior Poster

Good experience :)
Would you consider GUI-lizing it so that lazy people will use it!
add logging, try to repair and so forth.

Tech B 48 Posting Whiz in Training

I wouldn't know how to go about repairing a zip, and I think it gives false negitaves as well. Windows and 7Zip unzipped the "corrupt" ones just fine with no error.

I may make it a GUI, but the CLI is super simple to use.

I just got three new arduinos, a Ethernet shield, two motor drivers, and a whole lot of ideas. So I probably wont pick this script up for a while.

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.