I've tried multiple approaches to unzipping a file with Python, but each approach ends up with the wrong created time (because Python created a new copy of that file, not truly extracting it from the zipped file). For example, a file created on 2012-12-21 will show a creation date of today when extracted with Python, but if I use something else (like WinZip) the file creation time is not changed.
Is there a way to unzip the file using Python without changing the creation time?
@Jason Sperske, here is the code I am using:
zf = zipfile.ZipFile(fn)
for name in zf.namelist():
filename = os.path.basename(name)
zf.extract(name, filepath)
zf.close()
another version:
zf = zipfile.ZipFile(fn)
for name in zf.namelist():
source = zf.open(name)
target = open(os.path.join(filepath, filename), "wb")
with source, target:
shutil.copyfileobj(source, target)
I also called winzip from within python, it works but it's annoying. It opens lots of windows explore windows.