Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Python (http://www.velocityreviews.com/forums/f43-python.html)
-   -   keep original date and time of unzipped files (http://www.velocityreviews.com/forums/t319491-keep-original-date-and-time-of-unzipped-files.html)

Bartolomé Sintes Marco 07-10-2003 03:07 PM

keep original date and time of unzipped files
 
Hi,

In this mail,
http://www.mail-archive.com/kragen-h.../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



Dan Bishop 07-10-2003 11:33 PM

Re: keep original date and time of unzipped files
 
"Bartolomé Sintes Marco" <BartolomeSintes@ono.com> wrote in message news:<hjfPa.26867$FN3.2232703@news.ono.com>...
> Hi,
>
> In this mail,
> http://www.mail-archive.com/kragen-h.../msg00030.html
> Kragen Sitaker explained how to unzip a file in Python

....
> 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?


You can change a file's date and time with

os.utime(filename, (accessTime, modificationTime))


All times are GMT. The time now is 11:40 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.