【问题标题】:Call Winzip32.exe with parameter with c#用c#调用带参数的Winzip32.exe
【发布时间】:2012-02-25 13:39:04
【问题描述】:

我想通过我的控制台应用程序压缩文件夹,这就是我使用类似的东西的原因

public void DoWinzip(string zipName, string password, string folderName)
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();
            startInfo.FileName = "C:\\Program Files\\WinZip\\winzip32.exe";
            startInfo.Arguments = string.Format("-min -eZ {0} {1}", zipName, folderName);

            try
            {
                // Start the process with the info we specified.
                // Call WaitForExit and then the using statement will close.
                using (Process exeProcess = Process.Start(startInfo))
                {
                    exeProcess.WaitForExit();
                }
            }
            catch(Exception ex)
            {
                // Log error.
            }

        }

但这会给我类似 winzip 参数验证错误之类的错误。我哪里做错了?

Update

我在 -eZ 上拼写错误,实际上它可能是 -ex 等等……但另一个问题是 winzip 会打开自己的窗口。我为它写了-min 但是它打开了。

【问题讨论】:

  • 为什么不使用 SharpZipLib (icsharpcode.net/opensource/sharpziplib)?然后您就可以完全控制压缩过程。
  • 我这样做很好,但它提供的 zip 文件的 MB 大小比 winzip 大

标签: c# .net-3.5 winzip


【解决方案1】:

也许您正在传递带有空格的路径(在 zipNamefolderName 参数中)而不用双引号括起来。

【讨论】:

    【解决方案2】:

    您可以通过使用 ProcessStartInfo.WindowStyle 属性来避免打开窗口

    试试这个:

    ProcessStartInfo startInfo = new ProcessStartInfo();
    startInfo.FileName = "C:\\Program Files\\WinZip\\winzip32.exe";
    startInfo.WindowStyle = ProcessWindowStyle.Hidden;
    

    【讨论】:

      【解决方案3】:

      http://www.rondebruin.nl/parameters.htm -> 看着我认为代码是:

      startInfo.Arguments = string.Format("-e {0} {1}", zipName, folderName);

      【讨论】:

      • 另外,也许在设置 startInfo.Arguments 后尝试调试它们,以确保您确实传递了所需的输入。
      【解决方案4】:

      -eZ 选项是什么?我认为这是你的问题

      我认为以下是确定压缩方法的唯一选项。

      -ex = eXtra

      -en = 正常

      -ef = 快

      -es = 超级快

      -e0 = 不压缩

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-07-14
        • 2018-09-27
        • 1970-01-01
        • 1970-01-01
        • 2010-10-11
        • 1970-01-01
        相关资源
        最近更新 更多