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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:17:40+00:00 2026-06-12T18:17:40+00:00

I ran the following code: import zipfile import glob import datetime import os from

  • 0

I ran the following code:

import zipfile
import glob
import datetime
import os 
from collections import defaultdict
from shutil import copyfile

src = 'X:\\' 

for name in glob.glob('X:\*'):  
    print name

dict_date = defaultdict(lambda : defaultdict(list))
for fil in os.listdir(src):
        if os.path.isfile(os.path.join(src, fil)):
        date, logs = fil.split('_')[0], fil.split('_')[2]
        dict_date[date][logs].append(fil)

for date in dict_date:
    for logs in dict_date[date]:
        try:
            os.makedirs(os.path.join(src, date, logs))
            except os.error:
            pass
        for fil in dict_date[date][logs]:
            copyfile(os.path.join(src, fil), os.path.join(src, date, logs, fil))



for date in dict_date:
    with ZipFile(os.path.join(path, '{0}.zip'.format(date)), 'w') as myzip:
        for logs in dict_date[date]:
            for fil in os.listdir(os.path.join(path, date, logs)):
                if fil.endswith('.log'):
                    myzip.write(os.path.join(path, date, logs, fil))

Here are the results :

>>> 
X:\082012
X:\092012
X:\20120830
X:\20120830_7Days_ISDA_Logs_HS.zip
X:\20121001
X:\20121002
X:\20121003
X:\20121004
X:\20121005
X:\20121006
X:\20121007
X:\20121008
X:\20121009
X:\20121010
X:\20121011

Traceback (most recent call last):
  File "C:\Documents and Settings\tyoffe\Desktop\isda_zip.py", line 31, in <module>
    with ZipFile(os.path.join(path, '{0}.zip'.format(date)), 'w') as myzip:
NameError: name 'ZipFile' is not defined
>>> 
  • 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-12T18:17:41+00:00Added an answer on June 12, 2026 at 6:17 pm

    you should use:

    with zipfile.ZipFile(os.path.join(path, '{0}.zip'.format(date)), 'w') as myzip: 
    

    or you should do:

    from zipfile import ZipFile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I ran the following code to pull files from windows git repository. git pull
I ran the following code in PHPAdmin's terminal: SELECT COUNT( * ) FROM User
I ran the following code, but nothing came up on the console.... #include <stdio.h>
I ran across the following code in one of our in-house dlls and I
I ran across the following in a stored procedure: for select 1 from scan_queue
I downloaded the selenium-java-2.0a5.zip http://code.google.com/p/selenium/downloads/list and ran the following code: package org.openqa.selenium.example; import org.openqa.selenium.By;
I've tried to run the following code on Komodo IDE (for python): import unittest
I ran the following code to make sure that my public/index.html file has been
I ran the following code, and it stated is executed correctly. It is the
I ran the following code in codeblocks and got the output: 10 20 10

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.