keep original date and time of unzipped files

Bartolomé Sintes Marco BartolomeSintes at ono.com
Thu Jul 10 17:07:57 CEST 2003


Hi,

In this mail,
http://www.mail-archive.com/kragen-hacks@canonical.org/msg00030.html
Kragen Sitaker explained how to unzip a file in Python

#!/usr/local/bin/python
# learn how to use zipfile module

import sys, zipfile, os, os.path

def unzip_file_into_dir(file, dir):
    os.mkdir(dir, 0777)
    zfobj = zipfile.ZipFile(file)
    for name in zfobj.namelist():
        if name.endswith('/'):
            os.mkdir(os.path.join(dir, name))
        else:
            outfile = open(os.path.join(dir, name), 'wb')
            outfile.write(zfobj.read(name))
            outfile.close()

def main():
    unzip_file_into_dir(open(sys.argv[1]), sys.argv[2])

if __name__ == '__main__': main()

The unzipped files date and time are not the original ones, but
when the unzipping is done. Is there a way to keep the
original files date and time?

Thanks,
Barto






More information about the Python-list mailing list