Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8596863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:46:56+00:00 2026-06-12T00:46:56+00:00

I must use Python 2.6! This is a task that I really want to

  • 0

I must use Python 2.6!
This is a task that I really want to automate, the situation is static and once I create this, I’ll be golden (good).
I must create one, stand alone script (in Idle, I hope) that will:

  1. Unzip a single original zipfile (in_Zip) to the contents of the folder that the zipfile currently resides.
  2. Go to the unique (NON ZIPPED) folders (actually student usernames ‘aforker’, ‘allisw99’, ‘btaylor7’, etc) that result from step 1. (there may be anywhere from 1 to 40 of these unique student folders)
  3. within each unique folder (‘aforker’, ‘allisw99’, ‘btaylor7’, etc) extract any and all (could be none, could be 3 or 4) .zip files within, to their relative aforementioned unique folders (‘aforker’, ‘allisw99’, ‘btaylor7’, etc), while ‘navigating’ i.e. not getting hung up on possible .pdf or docx files that may or may not reside in the unique folders (‘aforker’, ‘allisw99’, ‘btaylor7’, etc)

This is what I’ve got so far: (and it ‘works’) (I’ll modify later so that I do not need to hard-code the original zipfile (in_Zip))

import os, os.path, zipfile
inZip = r'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\2012-09-18 Lab_2.zip'
outDir = r"D:\D_Drive_Documents\Student_Work_Sample_usecopy1"

z = zipfile.ZipFile(in_Zip,'a')
z.extractall(outDir)
zipContents = z.namelist()

print zipContents
z.close

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/']
'>>> '

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’ve had some suggestions on other forums/list serves, but they all involve trashing my current code and doing things in the windows command window, etc.
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.

Why? you ask? 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 @ 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)[0])
     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 <module>
    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/'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:46:57+00:00Added an answer on June 12, 2026 at 12:46 am

    With the help of nnoenneo (the other answerer above or below) Peter Otten, & Oscar Benjamin (on a different (python.org) forum), I was able to come up with the following code that works.

    import os, os.path, zipfile, arcpy
    
    in_Zip = r'D:\D_Drive_Documents\Student_Work_Sample_usecopy1\2012-09-18 Lab_2.zip'
    
    outDir = r"D:\D_Drive_Documents\Student_Work_Sample_usecopy1"
    
    z = zipfile.ZipFile(in_Zip,'r')
    
    z.extractall(outDir)
    
    zipContents = z.namelist()
    z.close()
    
    for item in zipContents:
        if item.endswith('.zip'):
            fullpath = os.path.join(outDir, item)
            x = zipfile.ZipFile(fullpath,'r')
            dest_path = os.path.dirname(fullpath)
            x.extractall(dest_path)
            x.close()
    

    If creating a tool in Esri’s ArcGIS, one would have to replace the ‘in_Zip’ line with:
    in_Zip = arcpy.GetParameterAsText(0)

    and the ‘outDir’ line with:
    outDir = os.getcwd()

    and then in the properties of the tool in ArcGIS browse to the .py file that contains the code above.

    Special Thanks to Peter Otten and Oscar Benjamin on python.org who have been helping me struggle through this since August 7th 2012!

    Regards,
    Greg

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When we must use DebuggerDisplay Attributes? What is the advantage of using this?
I have a ~2MB file that my Google AppEngine server must use (not serve)
I have an ArrayList of Routine objects and I must use this method to
I have a PhoneGap/Cordova project that means I must use a combination of JQuery
Making an adobe flex ui in which data that is calculated must use proprietary
I am trying to use networkx with Python. When I run this program it
I want to use Python to get the group id to a corresponding group
I must use goto in Python. I found entrians goto but my Python implementation
I am receiving this error when trying to use Python Server Pages with Mod_Python
I must use pkzip in my java program to zip (since standard java zip

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.