keep original date and time of unzipped files

Discussion in 'Python' started by Bartolomé Sintes Marco, Jul 10, 2003.

  1. Hi,

    In this mail,
    http://www.mail-archive.com//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
     
    Bartolomé Sintes Marco, Jul 10, 2003
    #1
    1. Advertising

  2. Bartolomé Sintes Marco

    Dan Bishop Guest

    "Bartolomé Sintes Marco" <> wrote in message news:<hjfPa.26867$>...
    > Hi,
    >
    > In this mail,
    > http://www.mail-archive.com//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))
     
    Dan Bishop, Jul 11, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?Q2hyaXM=?=

    window.open -- how to keep original page

    =?Utf-8?B?Q2hyaXM=?=, Apr 6, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    1,213
    Matt Berther
    Apr 7, 2005
  2. Chris Berg
    Replies:
    0
    Views:
    797
    Chris Berg
    Oct 27, 2003
  3. Peter Grison

    Date, date date date....

    Peter Grison, May 28, 2004, in forum: Java
    Replies:
    10
    Views:
    3,285
    Michael Borgwardt
    May 30, 2004
  4. Keith Cochrane
    Replies:
    2
    Views:
    626
    Keith Cochrane
    Aug 6, 2006
  5. RichardOnRails
    Replies:
    6
    Views:
    107
    RichardOnRails
    Aug 2, 2008
Loading...

Share This Page