在 C# 中提取 zip 文件时,lastwritetime 发生变化?
我正在使用 Sharpziplib version 0.86
来提取 zip 文件。它工作正常,但在通过代码提取 winzip 文件时,Lastwritetime 以秒为单位更改...
也使用过此 File.SetLastWriteTime(fullPath, theEntry.DateTime);
实际文件 Lastwritetime:4/8/2010 2:29:03PM
使用 winzip 压缩该文件并使用代码提取该文件后,提取的文件 Lastwritetime 更改为 4/8/2010 2:29:04PM
...对此有任何修复吗???
I am using Sharpziplib version 0.86
to extract a zip file. It is working fine but while extracting a winzip file through code,Lastwritetime is changing in seconds...
Have used this also File.SetLastWriteTime(fullPath, theEntry.DateTime);
Actual file Lastwritetime:4/8/2010 2:29:03PM
After zipping that file using winzip and while extracting that file using the code,extracted file Lastwritetime changes to 4/8/2010 2:29:04PM
...Is there any fix for this???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从 Sharpziplib 论坛收到此回复
您好,
这似乎是一个 WinZip 错误。我以前没有注意到这一点。
我做了这个测试:
1) 使用 WinZip 将文件添加到 zip 中。在 WinZip 中单击“属性和详细信息”。查看详细信息列表并找到文件时间戳。
2) 使用 SharpZipLib 创建具有相同输入文件的类似 zip 文件。在 Winzip 中打开结果并查看“属性”>“文件时间戳的详细信息。
我的输入文件的修改时间戳(文件属性)为 2010-12-14 15:51:28,在我的测试中,SharpZipLib 将其正确存储在 zip 中,而 WinZip 将其存储为 2010-12-14 15:51:30
换句话说,WinZip 在将其放入 zip 文件时增加了 2 秒。
解压后(使用 WinZip 或 SharpZip),修改后的时间为 15:51:30,而不是原来的 15:51:28。
令人惊讶的是,WinZip 中如此明显的错误竟然这么长时间都没有报告和修复。如果您有付费版本,您当然应该向他们提出错误。
我刚刚记得旧的 8.3 文件系统时间戳中大约有 2 秒的粒度。
快速谷歌发现了这个......
引用“原始DOS文件系统只有32个字节来表示目录中的文件。非常严格的8.3文件名和文件日期中有限的粒度(2秒)在Win32文件系统(VFAT)中得到了纠正)”。
来自 http://www.xxcopy.com/xxcopy15.htm
Zip 格式仅允许 2 秒标准时间戳条目中的粒度。日期和时间以标准 MS-DOS 格式编码。
可以包括可选的 NTFS 额外数据字段 (0x000a),该字段可以保存上次修改时间、上次访问时间和创建时间。 WinZip 似乎没有创建它。 SharpZip 将使用它(如果存在),但据我所知,在使用 FastZip 创建 zip 时不会创建它。这可能是添加到代码中的有用选项。如果使用 ZipFile,您当然可以手动创建它。
希望这有帮助,
大卫
I got this response from Sharpziplib Forum
Hi
This appears to be a WinZip bug. I have not noticed this before.
I did this test:
1) Use WinZip to add a file to a zip. In WinZip click Properties and Details. Look through the details list and find the file time stamp.
2) Use SharpZipLib to create a similar zip file with the same inputfile. Open the result in Winzip and look at the Properties > Details for the file time stamp.
My input file has a Modified timestamp (file properties) of 2010-12-14 15:51:28 and in my test, SharpZipLib stored it correctly in the zip, while WinZip stored it as 2010-12-14 15:51:30
In other words WinZip added 2 seconds when putting it into the zip.
After extracting (either with WinZip or SharpZip), the Modified is now 15:51:30 instead of the original 15:51:28.
it is amazing that such an obvious bug in WinZip can have gone unreported and unfixed for so long. If you have a paid version you should certainly raise a bug fault with them.
I just remembered something about 2 second granularity in the old 8.3 file system timestamps.
Quick google found this ...
Quote "Original DOS file system had only 32 bytes to represent a file in the directory. The very restrictive 8.3 filename and the limited granularity (2 second) in file date are corrected in the Win32 file systems (VFAT)."
from http://www.xxcopy.com/xxcopy15.htm
The Zip format only allows 2 second granularity in the standard time stamp entry.The date and time are encoded in standard MS-DOS format.
An optional NTFS Extra Data field (0x000a) can be included, which may hold last modification time, last access time and creation time. WinZip does not appear to create it. SharpZip will use it if present but as far as I can see, it is not created when using FastZip to create a zip. That might be a useful option to add to the code. You can certainly create it manually if using ZipFile.
Hope this helps,
David
我认为这可能只是操作系统造成的。我已经尝试过资源管理器中发生的情况。我有一个文本文件,修改后的时间戳为 17:06:45。我右键单击该文件并选择发送到 |压缩(zipped)文件夹。然后我右键单击新的 zip 文件并选择“全部解压...”,然后选择“下一步”、“下一步”、“完成”。现在,提取的文本文件的时间戳为 17:06:46。
当我使用 7-Zip 或 WinRar 时也会发生同样的情况。但只有在使用 .zip 文件时才会发生这种情况。如果我让他们创建 .7Z 或 .RAR 文件,则时间戳不会更改。
找到维基百科上的一篇关于 zip 格式的文章。如果你搜索“秒”,你会发现一个部分描述 ZIP 文件系统模仿 DOS FAT 文件系统,它的时间分辨率只有两秒。
I think it might just be the operating system that is causing this. I've tried what happens in Explorer. I've got a text file with a modified time stamp of 17:06:45. I right click on the file and choose Send to | Compressed (zipped) folder. Then I right click on the new zip-file and choose Extract All... followed by Next, Next, Finish. Now the extracted text file has a time stamp of 17:06:46.
The same happens when I use 7-Zip, or WinRar. But then it only happens when using a .zip file. If I let them create a .7Z or a .RAR file the time stamp isn't changed.
Found an article on Wikipedia about the zip format. If you search it for "seconds" you'll find a section describing that the ZIP file system mimics the DOS FAT file system, which only has a time resolution of two seconds.