Python stupid way to solve the problem of ZipFile decompression will change the file last modified time

Source: Internet
Author: User

#-*-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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.