This project is read-only.

File Last Write Time updated during zip creation

Jun 26, 2009 at 2:03 PM

Hi everybody,


I use the following code to create a zip file :

            using (ZipFile zip = new ZipFile() )
                zip.AddFile("c:\\test.txt", ".");


Everything works fine, but when i extract the zip file created, I notice that the Last Write Time of the file inside the zip has one second more compared to the original file.

For example :

Original file has the the following last write time : 10:30:12

The file inside the file zip ha the folloqing last write time : 10:30:13

Sometimes I notice that the difference is 2 seconds.

Any suggestion ?

Did I make some mistakes to create the zip file ?







Jun 26, 2009 at 3:50 PM

Hello Stefano.

The zip format stores timestamps in the same way that MS-DOS stored timestamps, in a format that allows a 2-second precision.  If the time of the file in the filesystem is  11:41:13, then when that file is added to a zip file, the timestamp stored with the entry within zip will be 11:41:12.   If you then extract the file, the extracted file should get the time of 11:41:12.  So you see there is the chance to lose 1 second in this round-trip.

It *shouldn't* lose more than one second.  I am surprised to hear that the difference is sometimes 2 seconds.   

What version of DotNetZip are you using?  Are you using DotNetZip to create the zip as well as to extract the zip?  If so, can you show me the code to extract?  If you are not using DotNetZip to extract, how do you extract?  Also, what do you mean when you talk of  "the timestamp within the zip"? How do you examine the timestamp within the zip?  With a different tool? Windows Explorer?  Something else?

There is one additional twist:  because of the poor precision of the DOS time format, PKWare extended the ZIP specification to allow storage of the timestamp in a much more precise manner.  As of version 1.8, DotNetZip uses this more precise manner, but not all other ZIP tools and libraries do so.  If you use DotNetZip 1.8 to create and extract a zip file, the newly extracted file will have the identical timestamp to the original file.  If you use DotNetZip to create the zip file, and some other tool to extract, it may be that the other tool does not handle and use the more precise timestamp within the zip file.  In this case, even though the more precise time is available, the other tool may use the +/- 2 second time, in which case you can see the 1 second difference.

If you give me some more information I can help unravel this mystery.

Jun 29, 2009 at 1:32 PM

Hi Cheeso,

thank you for your reply.

I am going to use the last version of the library the sooner the better; at the moment I have added a check about the last write time of the file I extract from the zip archive.

I am using the version 1.7 of the library.






Jun 29, 2009 at 5:12 PM

yes, I understand that you are comparing timestamps.  What I mean to ask is HOW do you check the timestamp and determine that the difference is 2 seconds or more?  and HOW do you create the archive?   I won't be able to help you unless you can provide some additional detail.  It may seem that I asked a lot of questions but they were all thoughtful ones.  None of them are useless.

As I explained , there is a rounding issue, because of the zip spec.  If you create the zip with a different zip tool and then extract it with DotNetZip, then I cannot guarantee how the timestamps are handled in the original zip archive.  If you compare the timestamps with a "dir" command in cmd.exe, it may be possible for rounding to indicate a 2s difference when in fact it is not 2 seconds.  And so on.  

You said you are using v1.7 - I asked about the version because I have previously made some updates to v1.7 and v1.8 to get this timestamp thing right.  But if you are not on the latest version then you may not have the updates.  On the other hand the updates primarily had to do with DST, not with 2 second deltas.

All of the details matter.

If you'd rather not answer all the questions, maybe you could send me a small example application, a console app, that reproduces the behavior you observe. That would be really helpful in explaining to me what you are doing and how you "see" the difference.