Created
November 10, 2015 12:58
-
-
Save lanfon72/e1234ad50e51f9313c48 to your computer and use it in GitHub Desktop.
a simply funtion for retain unzipfile timestamp.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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