Ionic Zip Library v1.9.1.6
GetEnumerator Method
Generic IEnumerator support, for use of a ZipFile in an enumeration.
Declaration Syntax
C# | Visual Basic | Visual C++ |
public IEnumerator<ZipEntry> GetEnumerator()
Public Function GetEnumerator As IEnumerator(Of ZipEntry)
public: virtual IEnumerator<ZipEntry^>^ GetEnumerator() sealed
Return Value
A generic enumerator suitable for use within a foreach loop.
Remarks
You probably do not want to call GetEnumerator explicitly. Instead
it is implicitly called when you use a foreach loop in C#, or a
For Each loop in VB.NET.
Examples
This example reads a zipfile of a given name, then enumerates the
entries in that zip file, and displays the information about each
entry on the Console.
CopyC#
using (ZipFile zip = ZipFile.Read(zipfile)) { bool header = true; foreach (ZipEntry e in zip) { if (header) { System.Console.WriteLine("Zipfile: {0}", zip.Name); System.Console.WriteLine("Version Needed: 0x{0:X2}", e.VersionNeeded); System.Console.WriteLine("BitField: 0x{0:X2}", e.BitField); System.Console.WriteLine("Compression Method: 0x{0:X2}", e.CompressionMethod); System.Console.WriteLine("\n{1,-22} {2,-6} {3,4} {4,-8} {0}", "Filename", "Modified", "Size", "Ratio", "Packed"); System.Console.WriteLine(new System.String('-', 72)); header = false; } System.Console.WriteLine("{1,-22} {2,-6} {3,4:F0}% {4,-8} {0}", e.FileName, e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"), e.UncompressedSize, e.CompressionRatio, e.CompressedSize); e.Extract(); } }
CopyVB.NET
Dim ZipFileToExtract As String = "c:\foo.zip" Using zip As ZipFile = ZipFile.Read(ZipFileToExtract) Dim header As Boolean = True Dim e As ZipEntry For Each e In zip If header Then Console.WriteLine("Zipfile: {0}", zip.Name) Console.WriteLine("Version Needed: 0x{0:X2}", e.VersionNeeded) Console.WriteLine("BitField: 0x{0:X2}", e.BitField) Console.WriteLine("Compression Method: 0x{0:X2}", e.CompressionMethod) Console.WriteLine(ChrW(10) & "{1,-22} {2,-6} {3,4} {4,-8} {0}", _ "Filename", "Modified", "Size", "Ratio", "Packed" ) Console.WriteLine(New String("-"c, 72)) header = False End If Console.WriteLine("{1,-22} {2,-6} {3,4:F0}% {4,-8} {0}", _ e.FileName, _ e.LastModified.ToString("yyyy-MM-dd HH:mm:ss"), _ e.UncompressedSize, _ e.CompressionRatio, _ e.CompressedSize ) e.Extract Next End Using