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 9223539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:06:06+00:00 2026-06-18T04:06:06+00:00

I’m uploading a zipped folder that contains a folder of text files, but it’s

  • 0

I’m uploading a zipped folder that contains a folder of text files, but it’s not detecting that the folder that is zipped up is a directory. I think it might have something to do with requiring an absolute path in the os.path.isdir call, but can’t seem to figure out how to implement that.

            zipped = zipfile.ZipFile(request.FILES['content'])
            for libitem in zipped.namelist():
                if libitem.startswith('__MACOSX/'):
                    continue
                # If it's a directory, open it
                if os.path.isdir(libitem):
                    print "You have hit a directory in the zip folder -- we must open it before continuing"
                    for item in os.listdir(libitem):
  • 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-18T04:06:07+00:00Added an answer on June 18, 2026 at 4:06 am

    The file you’ve uploaded is a single zip file which is simply a container for other files and directories. All of the Python os.path functions operate on files on your local file system which means you must first extract the contents of your zip before you can use os.path or os.listdir.

    Unfortunately it’s not possible to determine from the ZipFile object whether an entry is for a file or directory.

    A rewrite or your code which does an extract first may look something like this:

    import tempfile
    
    # Create a temporary directory into which we can extract zip contents.
    tmpdir = tempfile.mkdtemp()
    try:
        zipped = zipfile.ZipFile(request.FILES['content'])
        zipped.extractall(tmpdir)
    
        # Walk through the extracted directory structure doing what you
        # want with each file.
        for (dirpath, dirnames, filenames) in os.walk(tmpdir):
            # Look into subdirectories?
            for dirname in dirnames:
                full_dir_path = os.path.join(dirpath, dirname)
                # Do stuff in this directory
            for filename in filenames:
                full_file_path = os.path.join(dirpath, filename)
                # Do stuff with this file.
    finally:
        # ... Clean up temporary diretory recursively here.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a small JavaScript validation script that validates inputs based on Regex. I
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I have a text area in my form which accepts all possible characters from
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need to
I have a reasonable size flat file database of text documents mostly saved in

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.