#-*-CODING=GBK-*-import zipfiledef UnZip (Path, patht): #path for the file path that needs to be decompressed, patht for the extracted target directory f = zipfile. ZipFile (path, ' R ') print "Start extracting files ..." For file in F.namelist (): print "Extracting file:%s to%s"% (file, patht) F.extract (file, patht)
Under Windows Python uses the above code to extract the zip file, found that the decompression will be the last modification time of the file to extract the time, although the use of no impact, but it seems to always feel strange .... Over a long time module data really did not find out where in the module can add a parameter to keep the file last modified date, and finally a stupid way to write a! It's barely done. The ability to retain the last modified date is as follows:
# -*- coding=gbk -*-import zipfiledef unzipnew (PATH, PATHT): #path for the file path that needs to be unzipped, patht the target directory to extract print "Start performing decompression function" F = zipfile. ZipFile (path, ' R ') for file in f.infolist () : d = file.date_time gettime = "%s/%s/%s %s:%s" % (D[0], d[1], d[2], d[3] , d[4]) f.extract (file, patht) filep = os.path.join (Patht, file.filename) print "Recover files: Last Modified time for%s" % filep timearry = time.mktime (Time.strptime (gettime, '%Y/%m/%d %H:%M ')) &nbsP; os.utime (filep, (Timearry, timearry))
Python stupid way to solve the problem of ZipFile decompression will change the file last modified time