Skip to content

Instantly share code, notes, and snippets.

@lanfon72
Created November 10, 2015 12:58
Show Gist options
  • Select an option

  • Save lanfon72/e1234ad50e51f9313c48 to your computer and use it in GitHub Desktop.

Select an option

Save lanfon72/e1234ad50e51f9313c48 to your computer and use it in GitHub Desktop.
a simply funtion for retain unzipfile timestamp.
import os
import time
from zipfile import ZipFile
def unpack(filename, extract_dir=None):
if not extract_dir:
extract_dir = os.path.basename(filename).replace('.zip', '')
with ZipFile(filename) as zf:
for zi in zf.infolist():
target = zf.extract(extract_dir)
date_time = time.mktime(zi.date_time + (0,0,-1))
os.utime(target, (date_time, date_time))
return extract_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment