[Tutor] Unzipping a Zip of folders that have zips within them that I'd like to unzip all at once.
gnj091405 at gmail.com
Mon Sep 24 03:22:51 CEST 2012
> > z.close
> You need to have round brackets to actually call the close method, i.e.:
> > ----------------------------------------
> > It works, I get the following in the Python Shell:
> > '>>> ================================ RESTART
> > ================================'
> > '>>>'
> > ['Lab_2/aforker/', 'Lab_2/aforker/aforker_Lab2.zip',
> > 'Lab_2/allisw99/', 'Lab_2/allisw99/allisw99_Lab2.zip',
> > 'Lab_2/allisw99/allisw99_Lab2_Bonus.pdf', 'Lab_2/allisw992/',
> > 'Lab_2/allisw992/allisw99_Lab2_Bonus.pdf', 'Lab_2/btaylor7/',
> > 'Lab_2/btaylor7/2nd_btaylor7_Lab2.zip',
> > 'Lab_2/btaylor7/btaylor7_Lab2.zip', 'Lab_2/']
> Did you mean to have the paths of folders (e.g. 'Lab_2/aforker') in the
> same list as the paths of zip-files (e.g. 'Lab_2/aforker/aforker_Lab2.zip')?
Actually, I just used the 'zipContents = z.namelist() to see if I
could get some sort of positive result of my initial unzip.
It was just so I could see what I was getting.
but, I see that you're correct in noticing that i do use that namelist
in the next block of code, which (as you point out) isn't going to
> > '>>> '
> > But, what I can't figure out is how to get 'into' each unique folder:
> > aforker, allisw99, etc. and then extract any and all zips within
> > 'aforker', 'allisw99', etc.
> > I have no doubt that the suggestions posted here will work, but they
> > all seem to get away from a single .py file and....
> > a) I can't get them to work, and
> > b) it doesn't really help me because I need ONE stand alone .py file
> > to make this all work in ArcGIS.
> I don't know what ArcGIS is but if it runs Python then I'm sure that it
> can be done with a stand alone .py file.
ArcGIS is Esri's ArcGIS Analysis/Mapping software, that uses python
for it's scripts.
And, I hope that you are correct, (that I can get one stand alone .py
file to work.
If I can, I KNOW I can make the minor modifications necessary to use
in the graphic interface.
> > I will be using this to create an ArcGIS 'tool' that requires one
> > script (at least for me to comprehend it) :-)
> > Thank you in advance for any and all suggestions, tips etc.
> > For the record, I did try the following (to at least try
> > something....) at the bottom of the code above:
> > -----------------------
> > for item in zipContents:
> > itemLoc = os.path.join(outDir,item)
> > y = zipfile.ZipFile(itemLoc,'a')
> > y.extractall(os.path.aplit(itemLoc))
> > y.close
> > ------------------------
> > but I get the following error:
> > Traceback (most recent call last): File
> > "D:\D_Drive_Documents\Scripts\Unzip_a_zip_of_zips\Scripts\unzip_a_zip.py",
> > line 50, in y = zipfile.ZipFile(itemLoc,'a') File
> > "C:\Python26\ArcGIS10.0\lib\zipfile.py", line 687, in init self.fp =
> > open(file, modeDict[mode]) IOError: [Errno 13] Permission denied:
> > 'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\Lab_2/aforker/'
> You're trying to open the directory as if it were a zipfile. You should
> pass in the path to a zipfile not to a folder.
Agreed, but how do I do that "pass in the path to a zipfile'?
Using an if statement I presume?
> Also you're opening the files in append mode 'a'. I think you really want
> read-only mode 'r'.
fixed it to 'r' mode. (rookie mistake)
> > I guess my first issue is to resolve the 'Permission denied' problem.
> > And, I know I need an 'if' statement, somehow...
Yes, the permission denied problem seems to be the first real
obstacle, but I can't figure it out.
I tried searching online but everything I found to try, didn't work.
> Remove the folder paths from the list of paths.
How can I remove the folder paths from the list of paths?
More information about the Tutor