Trying to create a zip file with yesterdays date. I think I got everything, but I am getting module has no object attrib error. Any ideas?

import os
import zipfile
import datetime

today = datetime.date.today()
yesterday = (today + datetime.timedelta(days=-1))

file = zipfile.Zipfile("CT" + yesterday.strftime('%m%d%y') +".zip", "w")
files = os.listdir("c:\\crunchtime")
for f in files:
    file.write(f)

Okay, noticed the syntax issue, but now when it runs, I get a message saying error 2 windows cannot find file specified. I am a bit perplexed. Should I put a chdir to tell the program where the files are? I thought that was passed from the listdr.

import os
import zipfile
import datetime

today = datetime.date.today()
yesterday = (today + datetime.timedelta(days=-1))

tFile = zipfile.ZipFile("c:\\crunchtime\\CT" + yesterday.strftime('%m%d%y') +".zip", "w")
files = os.listdir("c:\\crunchtime")
for f in files:
    tFile.write(f)

I would rewrite your code like this:

import os
import zipfile
import datetime

today = datetime.date.today()
yesterday = (today + datetime.timedelta(days=-1))

zfilename = "c:\\crunchtime\\CT" + yesterday.strftime('%m%d%y') +".zip"
# test it
print zfilename

tFile = zipfile.ZipFile(zfilename, "w")
directory = "c:\\crunchtime"
files = os.listdir(directory)
for file in files:
    if os.path.isfile(file):
        fullpath = os.path.join(directory, file)
        tFile.write(fullpath)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.