Overwiew

Archives that consist of entries have CreateEntries method for compressing whole directory. Such methods respect directory structure and compose recurrently for all subfolders.
Also you can add a single file entry to arbitrary subdirectory wherever to the archive.

How to Zip a folder

When striving to compress a folder while preserving its structure, consider employing Aspose.ZIP’s intuitive features. Utilize the Archive instance’s compression settings, such as the PreserveDirectoryRoot property, during initialization to maintain the folder structure. By incorporating this setting, the compressed archive will reflect the original hierarchy, ensuring organized data representation. This proves especially advantageous when dealing with extensive folder structures, as it simplifies navigation and retrieval of specific files without the necessity for decompression. Aspose.ZIP .Net API provides a seamless solution to compress folders while respecting their inherent structures, enhancing the efficiency of data storage and retrieval processes.
Sample:

    using (Archive archive = new Archive())
    {
        DirectoryInfo corpus = new DirectoryInfo(@"D:\Data");
        archive.CreateEntries(corpus);
        archive.Save("archive.zip");
    }

Sample 2:

Compose hierarchical structure with CreateEntry method

    using (Archive archive = new Archive())
    {
        FileInfo fi1 = new FileInfo("image.bmp");
        FileInfo fi2 = new FileInfo("lyrics.txt");
        archive.CreateEntry("data\\pictures\\photo.bmp", fi1);
        archive.CreateEntry("data\\text\\song.txt", fi2);
        archive.Save("archive.zip");
    }

How to Zip a Folder with .NET

CreateEntries method has optional second parameter includeRootDirectory which indicates if the root directory needs to be included to the archive. Default is true, so in the above sample all of archive entries will be located inside “Data” folder. If you want only directory content to be added then pass false there. There will be folders "pictures" and "text" within folder "data" in the resulting archive.

How to Compress Folder in 7-ZIP Respecting its Structure

7Zip compression method that preserves the folder structure during archiving. This can improve the organization and convenience of working with archives. CreateEntries is the analogue method of 7Z archive. It also has includeRootDirectory parameter.
To use 7-Zip compression with a method that preserves the folder structure during archiving, an example demonstrating how to achieve this is provided below.

Create archive from directory

    using (SevenZipArchive archive = new SevenZipArchive())
    {
        DirectoryInfo corpus = new DirectoryInfo(@"D:\Data");
        archive.CreateEntries(corpus);
        archive.Save("archive.7z");
    }

7-ZIP Archive Overview

7-Zip, a versatile archiving utility, excels with its high compression ratio and support for various formats. Notably, 7-Zip offers a convenient way to add files without applying compression. Users can seamlessly integrate files into a 7-Zip Archives while preserving the original data structure, ensuring the integrity of their content.

How to Compress a Folder in TAR While Keeping Its Structure

Compressing folders in TAR format is a common practice for efficient storage and transfer of data. However, preserving the folder structure during compression is crucial for maintaining the organization and accessibility of the archived files. Archiving folders in TAR format provides a convenient solution for this problem. In spite of this, traditional compression methods often disregard the original folder structure, making it difficult to navigate and locate specific files within the archive. Default, TAR compression does not maintain the original folder structure, which can be inconvenient for users who need to access specific files within the archive. Apart from compression, tar archive has the same method for archiving whole directory.

Sample 1:

Create archive from directory

    using (TarArchive archive = new TarArchive())
    {
        archive.CreateEntries(@"D:\Data");
        archive.Save("archive.tar");
    }

Sample 2:

Combine archiving directory and single file

    using (Archive archive = new Archive())
    {
        FileInfo fi1 = new FileInfo("image.bmp");
        FileInfo fi2 = new FileInfo("lyrics.txt");
        archive.CreateEntry("data\\pictures\\photo.bmp", fi1);
        archive.CreateEntry("data\\text\\song.txt", fi2);
        archive.Save("archive.zip");
    }

TAR Archive Overview

TAR (Tape ARchive) is a popular file format for archiving and compressing single files . It is a lossless format, meaning that no data is lost during compression. TAR files can be created on any operating system and are supported by a wide variety of software.

Advanced Compression Techniques in XAR with Preserving Folder Structure

XAR, a modern archive format, offers flexibility by allowing users to create archives while preserving the original folder structure. This unique approach caters to users who require advanced compression techniques without compromising file organization. Xar archive uses the same approach as all abovementioned formats.
Sample:

Create archive from directory

    using (FileStream xarFile = File.Open("archive.xar", FileMode.Create))
    {
        using (var archive = new XarArchive())
        {
            archive.CreateEntries(@"C:\folder", false);
            archive.Save(xarFile);
        }
    }

XAR Archive Overview

XAR simplifies the process of adding files without compression, providing users with flexibility in managing their archives. Utilizing XAR commands or compatible software tools, users can seamlessly integrate files into the archive without invoking compression algorithms. This straightforward method ensures that the original data structure remains intact, ready for retrieval when needed.

  

Support and Learning Resources

  
  

Aspose.Zip offers individual archive processing APIs for other popular development environments, listed below: