CompressDirectory

ArchiveFactory.CompressDirectory method

Compresses the specified directory into an archive file using the provided archive format.

public static void CompressDirectory(string path, string outputFileName, 
    ArchiveFormat archiveFormat)
ParameterDescription
pathThe path to the directory that will be compressed.
archiveFormatThe format of the archive to create (e.g., zip, rar, tar, etc.).

Exceptions

exceptioncondition
DirectoryNotFoundExceptionThrown if the directory specified by path does not exist.
ArgumentExceptionThrown if path is null or an empty string.
NotSupportedExceptionThrown if the specified archiveFormat is not supported or recognized.

Remarks

This method will create an archive file at the location specified by the path parameter. The name of the archive file will typically be the directory name followed by the appropriate file extension based on the archiveFormat. The directory itself is not modified or deleted.

Examples

Here is an example of how to use the CompressDirectory method:

string directoryPath = @"C:\path\to\your\directory";
ArchiveInfo.ArchiveFormat format = ArchiveInfo.ArchiveFormat.Zip;
ArchiveFactory.CompressDirectory(directoryPath, format);
// This will create a zip file with the contents of the directory at the specified path.

See Also