1

i'm using python2.7 to extract zip files under windows - created by 7z.exe. Now if i use zip.extractall(), the extracted files have a modfied date, which causes some problems in later prosessing these file. Now, how can i preserve the timestamp of each file extracted. I think i want the "last modified" attribute? Here is my unzip function:

def unzip(src, dst):
    lst = []
    try:
        dst = os.path.normpath(dst)
        if not os.path.exists(dst):
            os.makedirs(dst)

        os.chdir(dst)
        src = os.path.normpath(src)
        zip = zipfile.ZipFile(src, "r")
        lst = zip.namelist()
        zip.extractall()
        zip.close()

    except zipfile.BadZipfile as e:
        print "Zip error. Couldn't open zip file:", src

    except IOError as e:
        print "I/O-Error while extracting", \
              os.path.basename(src), \
              "({0}): {1}".format(e.errno, e.strerror)

    return lst
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Andreas Müller
  • 210
  • 2
  • 10

0 Answers0