0

I am using approach described in this answer to unzip a zip file into destination directory.

The problem I am having is, the files in destination folder (which are results of unzip) having the unzipped timestamp instead of the original "zipped" version file timestamp.

Any idea how can I retain the original timestamp?

Based on my research it seems, I might need to use something like os.Chtimes(...) function to reset the timestamp after file copy, which seems little bit cumbersome. Any suggestions?

kosa
  • 65,990
  • 13
  • 130
  • 167
  • 2
    Either you call [`os.Chtimes`](https://pkg.go.dev/os#Chtimes) or you find a package that does it for you. Either way there's no way to create files with a certain timestamps without setting those timestamps. – JimB Dec 17 '19 at 17:51
  • @CeriseLimón Thanks. I got the date part working fine by using chtimes and modtime, but the "time" part is not correct. Seems UTC to EST messing up. Need to find out a way to get those corrected. – kosa Dec 17 '19 at 18:38
  • Use [Modified](https://godoc.org/archive/zip#FileHeader.Modified) instead of [ModTime](https://godoc.org/archive/zip#FileHeader.ModTime). –  Dec 17 '19 at 20:49
  • @iLoveReflection I am using Modified, see the documentation describing ModTime is deprecated. Thanks! – kosa Dec 17 '19 at 20:56

0 Answers0