Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > keep original date and time of unzipped files

Reply
Thread Tools

keep original date and time of unzipped files

 
 
Bartolomé Sintes Marco
Guest
Posts: n/a
 
      07-10-2003
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


 
Reply With Quote
 
 
 
 
Dan Bishop
Guest
Posts: n/a
 
      07-10-2003
"Bartolomé Sintes Marco" <(E-Mail Removed)> wrote in message news:<hjfPa.26867$(E-Mail Removed)>...
> 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))
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird: Just unzipped ruby-1.9.0-2.zip -- no Ruby.exe RichardOnRails Ruby 6 08-02-2008 06:29 PM
w3.org suggestion .. page, date, time and topic, date, time code (wish list). Keith Cochrane HTML 2 08-06-2006 06:57 AM
Date, date date date.... Peter Grison Java 10 05-30-2004 01:20 PM
Extract original date/time photo taken from jpg Chris Digital Photography 4 12-24-2003 12:33 AM
Retreiveing photos with the original time/date stamps Eric Edwards Digital Photography 2 08-08-2003 11:15 PM



Advertisments