Geoffroy’s Weblog

February 25, 2009

Zip and Unzip Files with ZipGenius

Filed under: C#, Compression, System.Diagnostics.Process, Zip — gseive @ 12:12 am

Once, I had to uncompress a tar file and looking around I found this great utility, ZipGenius. It works great and it’s free!

It can also be run from the command line which mean it can be encapsulated in a batch file or even better, if  you need more programmatic control, it can be embedded in a .NET program.

For the details of the command line options go to: http://zipgenius.altervista.org/zg6/eng_zghlp/.

Here is an example of some C# code calling ZipGenius with System.Diagnostics.Process.Start:

using System;
using System.Collections.Generic;

namespace ZipGeniusProject
    // more information on the command line options at
    // http://zipgenius.altervista.org/zg6/eng_zghlp/
{
    class ZipGenius
    {
        static void Main(string[] args)
        {
            List<string> commandPieces = new List<string>();
            string command = @"""c:\Program Files\ZipGenius 6\zg.exe""";
            commandPieces.Add(" -add ");
            commandPieces.Add(@"""C:\My Folder\Test.zip""");
            commandPieces.Add(" C5 K0 +");
            commandPieces.Add(@"""C:\Drivers\C600\BIOS\*.*""");
            string zgArgs = String.Concat(commandPieces.ToArray());
            System.Diagnostics.Process.Start(command, zgArgs);

            // Another option is to use a batch file.
            // It's simpler but offers less programatic flexibility.
            // System.Diagnostics.Process.Start(@"c:\myscript.bat");
        }
    }
}

Create a free website or blog at WordPress.com.