How do I programmatically check the date of a file in a Zip archive?
Question
Given that I have a zip file called archive.zip
that contains a file called customerData
, how can I programmatically check the date of the file inside archive.zip
? I'm using the command-line Winzip utility wzunzip, but I wouldn't object to possibly using something else.
I'm writing a .net application that will periodically read data from customerData
. The file is very big and I want to abort the operation without extracting customerData
if the date stamp has not been updated, indicating that there is new data to read.
Solution
Via http://dotnetzip.codeplex.com/. There is no native way (that I know) to do that.
Example Code:
ZipFile z = ZipFile.Read(@"C:\archive.zip");
foreach (ZipEntry zEntry in z)
{
Console.WriteLine(zEntry.LastModified.ToString());
}
OTHER TIPS
I think the easiest .NET API is DotNetZip, but SharpLibZip works as well. There are a number of pay libraries of which I've and enjoyed and successfullly used ChilCat.
UPDATE: If you don't mind scripting. 7zip command line provides the info
C:\temp\XpsTest>"c:\Program Files\7-zip\7z.exe" l "39 Clues.xps"
7-Zip 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03
Listing archive: 39 Clues.xps
Date Time Attr Size Compressed Name
------------------- ----- ------------ ------------ ------------------------
2009-09-10 23:06:58 ..... 160 212 FixedDocumentSequence.fdseq
...
If I may be so bold, it sounds unlikely that checking a zip file periodically is a good solution to many problems, unless you have no control over how this data is being delivered to you?
If you could post a little more information about the problem/situation you are dealing with, I dare say the crew here might be able to come up with some more interesting possible solutions.?
A bit off-topic, but sometimes answering a problem with the right question isn't as helpful as getting an easier and cleaner problem to solve.. at least I like to think so.
Hope that helps..
Set to the date of extraction, not the date the folder was originally created, although viewing the archive in 7zip file manager does show that the original folder creation date is recorded...