ZipArchive.AddDirectory Method


Adds a directory including sub-directories and files to current zip file.

[Visual Basic]
Public Sub AddDirectory( _
    directory As String, _
    password As String _
)
[C#]
public void AddDirectory(
    string directory,
    string password
);
[C++]
public: void AddDirectory(
    String* directory,
    String* password
);
[JScript]
public function AddDirectory( 
    directory: String,
    password: String
);

Parameters

directory
The directory full path to be compressed.
password
The password for encryption, it can be null.

Example

[Visual Basic, C#, C++] The following example demonstrates how to compress/decompress file with EACompression Zip Component. This sample doesn't demonstrates the events, please refer to Samples section to get the full samples of EACompression.

[Visual Basic]
Imports EACompression

Sub Zip()
    Try
        Dim oZip As New ZipArchive("TryIt")
        oZip.Create("c:\test.zip", True)   'create a new zip file
        Dim password As String = ""
        'add a single file to zip file.
        oZip.AddFile("c:\test.gif", "", password)
        'add all files and sub-directory in temp folder to zip archive
        oZip.AddDirectory("c:\temp", password)
    Catch ep As Exception
        Console.Write(ep.Message)
    End Try
End Sub

[C#]
using System;
using System.Collections;
using EACompression;

void Zip()
{
    try
    {
        ZipArchive oZip = new ZipArchive( "TryIt" );
        oZip.Create( "c:\\test.zip", true ); //create a new zip file;
        string password = "";
        //add a single file to zip file.
        oZip.AddFile( "c:\\test.gif", "", password );
        //add all files and sub-directory in temp folder to zip archive
        oZip.AddDirectory( "c:\\temp", password ); 
    }
    catch( Exception ep )
    {
        Console.Write( ep.Message );
    }
}

[C++]
using namespace System;
using namespace System::Collections;
using namespace EACompression; 

void Zip()
{
    try
    {
        ZipArchive *oZip = new ZipArchive( S"TryIt" );
        oZip->Create( S"c:\\test.zip", true ); //create a zip file;
        String *password = S"";
        //add a single file to zip file.
        oZip->AddFile( S"c:\\test.gif", S"", password );
        //add all files and sub-directory in temp folder to zip archive
        oZip->AddDirectory( S"c:\\temp", password ); 
    }
    catch( Exception *ep )
    {
        Console::Write( ep->Message );
    }
}