Listing contents of an archive

This topic demonstrates how to get a listing of all of the files stored within an archive.

To list the files stored within an archive, you need to perform the following steps:

  1. Create a new Zip object.
  2. Open an existing archive file or create a new archive using Open methods.
  3. Call ListAll or ListDirectory to retrieve the desired list of file information within the archive.

This example shows how to list all files stored within an archive:

C#:

using System;
using Atp.Compression;
using Atp.IO;
namespace CSharp
{
   static class ListAll
   {
       [STAThread]
       static void Main()
       {
           // Open an existing file
           Zip zip = new Zip("test.zip");
           // List .doc files.
           ZipFileInfoCollection col = zip.ListAll("*.doc");
           foreach (ZipFileInfo archiveFile in col)
           {
               Console.WriteLine("File Name: " + archiveFile.Name);
               Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +
                   archiveFile.LastWriteTime.ToShortTimeString());
               Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);
               Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);
               Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);
               Console.WriteLine("    CRC: " + archiveFile.Checksum);
               Console.WriteLine("    Stored Path: " + archiveFile.DirectoryPath);
               Console.WriteLine("    Comment: " + archiveFile.Comment);
           }
           // List files with zero length.
           col = zip.ListAll(SearchCondition.SizeEqualTo(0L));
           foreach (ZipFileInfo archiveFile in col)
           {
               Console.WriteLine("File Name: " + archiveFile.Name);
               Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +
                   archiveFile.LastWriteTime.ToShortTimeString());
               Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);
               Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);
               Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);
               Console.WriteLine("    CRC: " + archiveFile.Checksum);
               Console.WriteLine("    Stored Path: " + archiveFile.DirectoryPath);
               Console.WriteLine("    Comment: " + archiveFile.Comment);
           }
           // List all files.
           col = zip.ListAll();
           foreach (ZipFileInfo archiveFile in col)
           {
               Console.WriteLine("File Name: " + archiveFile.Name);
               Console.WriteLine("    Last Write Time: " + archiveFile.LastWriteTime.ToShortDateString() + " " +
                   archiveFile.LastWriteTime.ToShortTimeString());
               Console.WriteLine("    Uncompressed Size: " + archiveFile.Length);
               Console.WriteLine("    Compressed Size: " + archiveFile.CompressedLength);
               Console.WriteLine("    Compression Rate: " + archiveFile.CompressionRate);
               Console.WriteLine("    CRC: " + archiveFile.Checksum);
               Console.WriteLine("    Stored Path: " + archiveFile.DirectoryPath);
               Console.WriteLine("    Comment: " + archiveFile.Comment);
           }
           zip.Close();
       }
   }
}

VB.NET

Imports Microsoft.VisualBasic
Imports System
Imports Atp.Compression
Imports Atp.IO
Module ListAll
    Sub Main()
        ' Open an existing file
        Dim zip As New Zip("test.zip")
        ' List .doc files.
        Dim col As ZipFileInfoCollection = zip.ListAll("*.doc")
        For Each archiveFile As ZipFileInfo In col
            Console.WriteLine("File Name: " & archiveFile.Name)
            Console.WriteLine(" Last Write Time: " & archiveFile.LastWriteTime.ToShortDateString() & " " & archiveFile.LastWriteTime.ToShortTimeString())
            Console.WriteLine(" Uncompressed Size: " & archiveFile.Length)
            Console.WriteLine(" Compressed Size: " & archiveFile.CompressedLength)
            Console.WriteLine(" Compression Rate: " & archiveFile.CompressionRate)
            Console.WriteLine(" CRC: " & archiveFile.Checksum)
            Console.WriteLine(" Stored Path: " & archiveFile.DirectoryPath)
            Console.WriteLine(" Comment: " & archiveFile.Comment)
        Next archiveFile
        ' List files with zero length.
        col = zip.ListAll(SearchCondition.SizeEqualTo(0L))
        For Each archiveFile As ZipFileInfo In col
            Console.WriteLine("File Name: " & archiveFile.Name)
            Console.WriteLine(" Last Write Time: " & archiveFile.LastWriteTime.ToShortDateString() & " " & archiveFile.LastWriteTime.ToShortTimeString())
            Console.WriteLine(" Uncompressed Size: " & archiveFile.Length)
            Console.WriteLine(" Compressed Size: " & archiveFile.CompressedLength)
            Console.WriteLine(" Compression Rate: " & archiveFile.CompressionRate)
            Console.WriteLine(" CRC: " & archiveFile.Checksum)
            Console.WriteLine(" Stored Path: " & archiveFile.DirectoryPath)
            Console.WriteLine(" Comment: " & archiveFile.Comment)
        Next archiveFile
        ' List all files.
        col = zip.ListAll()
        For Each archiveFile As ZipFileInfo In col
            Console.WriteLine("File Name: " & archiveFile.Name)
            Console.WriteLine(" Last Write Time: " & archiveFile.LastWriteTime.ToShortDateString() & " " & archiveFile.LastWriteTime.ToShortTimeString())
            Console.WriteLine(" Uncompressed Size: " & archiveFile.Length)
            Console.WriteLine(" Compressed Size: " & archiveFile.CompressedLength)
            Console.WriteLine(" Compression Rate: " & archiveFile.CompressionRate)
            Console.WriteLine(" CRC: " & archiveFile.Checksum)
            Console.WriteLine(" Stored Path: " & archiveFile.DirectoryPath)
            Console.WriteLine(" Comment: " & archiveFile.Comment)
        Next archiveFile
        zip.Close()
    End Sub
End Module