Simple ZIP

Simple ZIP

Demonstrates how to create a ZIP archive and add files to it.

Usage

=====================================================================
SimpleZip.exe
=====================================================================

Adds files to a ZIP archive

Syntax: SimpleZip.exe zip-file-path [path-or-mask]
Example: SimpleZip.exe c:\archive.zip c:\data\*.txt

More info

The following code snippet is the core of the sample:

C#

// open or create a ZIP archive and add files to it
using (ZipArchive archive = new ZipArchive(@"c:\archive.zip"))
{
    ArchiveOperationResult result = archive.Add(
        @"c:\data\*",
        "/",
        TraversalMode.Recursive,
        TransferMethod.Copy,
        ActionOnExistingFiles.OverwriteAll
    );

    Console.WriteLine(
        "Added {0} file(s), {1} byte(s) to {2}.",
        result.FilesAffected,
        result.FilesUncompressedLength,
        archive.FilePath
    );
}

VB.NET

' open or create a ZIP archive and add files to it
Using archive As New ZipArchive("c:\archive.zip")
    Dim result As ArchiveOperationResult = archive.Add( _
        "c:\data\*", _
        "/", _
        TraversalMode.Recursive, _
        TransferMethod.Copy, _
        ActionOnExistingFiles.OverwriteAll)

    Console.WriteLine( _
        "Added {0} file(s), {1} byte(s) to {2}.", _
        result.FilesAffected, _
        result.FilesUncompressedLength, _
        archive.FilePath)

End Using

Included in

See also: