Setting file attributes on file creation from ZipFiles (solved)

Chris Withers chrisw at nipltd.com
Wed Mar 28 18:14:29 EST 2001


I posted this question a while ago, and now that I've found the answer I thought
I'd post it back ;-)

Anyway, the problem was setting the modified dates on files I was creating by
unzipping them from a ZipFile object.

You can do this using a function as follows:

from os import utime
from time import time,mktime

def unzip_with_date(zipefile,filename):
    f = open(filename,'wb')
    f.write(zipefile.read(filename))
    f.close()
    utime(filename,(time(),round(mktime(zipefile.getinfo(filename).date_time +
(0,0,-1)))))

Maybe that could be made into a method and included in ZipFile?

cheers,

Chris

PS: For the curious, I found out how to do this by looking at shutil.py; I love
a language where the source for the libraries is included :-)





More information about the Python-list mailing list