[Tutor] Unzip a zipfile, then unzip the zipfiles within the original zip

Gregory Lund gnj091405 at gmail.com
Tue Aug 7 19:10:54 CEST 2012


# neophyte .py/pyTutor user.
# I am also a university GIS lecturer. My students submit their lab
assignments (zipped up into one zipfile) to a depository, which I
download as a single zip containing all 40 students' zipfiles.
# Goal: unzip a zipfile of student zipfiles and then unzip each
students' zipfile ( to prevent me from having to unzip each students'
zipfile by hand. )
# eventually I'll turn this into a tool in ArcGIS, that will grade
some of their assignment, but for now, just want to get these extract
processes running in python.

# using (and want to use) 2.6 because I'm working with ArcGIS
# this is what I've got thus far:

#1 Unzip a single starting zipfile "initial_Zipfile" (that contains a
series of 40 individual zipfiles) into a single folder named whatever
it was originally named.

#2 Unzip all of the zipfiles within the 'initial_Zipfile' into their own folder.

## Actual  Code:

import zipfile, arcpy, os.path, os

#1 Defining a function to Unzip the initial (.zip) folder. (this worked fine)

def unzip_Orig(oZ):
    z = zipfile.ZipFile(oZ)
    z.extractall()
    return

q = "unzip_Unzip_Data_Test.zip"
unzip_Orig(q)

#2 my attempts to unzip each zipfile within the new folder below
(failed thus far)

mywd = os.getcwd()
zipList = os.listdir(mywd)
print zipList  #this didn't work, it printed the directory of where
the .py was stored.
#Zipfile.printdir() # returned "'Zipfile' is not defined.

#thoughts?

# Thanks
# Greg


More information about the Tutor mailing list