none
How can i split to volumes big archive zipped file with 7zip ?

    Question

  • In my code i used the 7zip wrapper SevenZipSharp.dll referenced it.

    In Form1 in a button click im doing:

    Compressions("photofiles.zip", tempphotos, outputphotos);

    And this is the Compressions method:

    private void Compressions(string zipFile,string sources,string OutPut)
            {
                try
                {
                    string zipFileName = zipFile;
                    string source = sources;
                    string output = OutPut;
                    string programFilesX86 = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFilesX86) + "\\Diagnostic Tool\\7z.dll";
                    if (File.Exists(programFilesX86))
                    {
                        SevenZipExtractor.SetLibraryPath(programFilesX86);
                    }
                    else
                    {
                        string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\7z.dll";
                        SevenZipExtractor.SetLibraryPath(path);
                    }
                    string programFiles = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ProgramFiles) + "\\Diagnostic Tool\\7z.dll";
                    if (File.Exists(programFiles))
                    {
                        SevenZipExtractor.SetLibraryPath(programFiles);
                    }
                    else
                    {
                        if (File.Exists(programFilesX86))
                        {
                            SevenZipExtractor.SetLibraryPath(programFilesX86);
                        }
                        else
                        {
                            string path = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "\\7z.dll";
                            SevenZipExtractor.SetLibraryPath(path);
                        }
                    }
                    SevenZipCompressor compressor = new SevenZipCompressor();
                    compressor.ArchiveFormat = OutArchiveFormat.Zip;
                    compressor.CompressionMode = CompressionMode.Create;
                    compressor.TempFolderPath = System.IO.Path.GetTempPath();
                    string t = Path.Combine(output, zipFileName);
                    
                    compressor.CompressDirectory(source, t);
                }
                catch (Exception err)
                {
                    Logger.Write("Zip file error: " + err.ToString());
                }
            }

    In the end i will have a zip file on my hard disk for example lets say the file is: test.zip and that the file size is 80mb.

    Now i want to use the 7zip(SevenZipSharp wrapper) and create/split this zip file to many small files each one 8mb in the same directory.

    I googled and tried to look in the 7zip documents i didnt find how to split the big zip file to some smaller zip files.

    Any idea how can i do it in my code in c# not with the 7zip.exe or something i need to do it right after it created the big zip file ?

    Maybe inside the Compressions method in the end.

    Sunday, August 11, 2013 9:10 AM

Answers

  • Hi,

    Try to specify the volume of the file:

    compressor.VolumeSize = 1024*1000*8;

    Or you may try DotNetZip, it's easy to split compressed files by using it. Example code:

    int SegmentsCreated ;
    using (ZipFile zip = new ZipFile())
    {
      zip.UseUnicode= true;  // utf-8
      zip.AddDirectory(@"MyDocuments\ProjectX");
      zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G") ;
      zip.MaxOutputSegmentSize = 100*1024 ; // 100k segments
      zip.Save("MyFiles.zip");
     
      SegmentsCreated = zip.NumberOfSegmentsForMostRecentSave ;
    }
    
    
    if SegmentsCreated comes back as 5, then you have the following files, each not more than 100kb in size.
    •MyFiles.zip
    •MyFiles.z01
    •MyFiles.z02
    •MyFiles.z03
    •MyFiles.z04


    Caillen
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by Chocolade1972 Friday, August 16, 2013 12:22 AM
    Monday, August 12, 2013 7:19 AM

All replies