2

I have to zip multiple files together using 7zip.exe. I have paths of two files say file1 and file2. I append the two paths using the following. string filetozip = file1+ "\"" + file2+" "; and do the below

        Process proc = new Process();
        proc.StartInfo.FileName = @"C:\Freedom\7-Zip\7z.exe";
        proc.StartInfo.UseShellExecute = false;
        proc.StartInfo.RedirectStandardError = true;
        proc.StartInfo.RedirectStandardInput = true;
        proc.StartInfo.RedirectStandardOutput = true;

       proc.StartInfo.Arguments = string.Format("    a -tzip \"{0}\" \"{1}\" -mx=9 -mem=AES256 -p\"{2}\"    ", destZipFile, filetozip , zipPassword);
        proc.Start();

        proc.WaitForExit();

        if (proc.ExitCode != 0)
        {
           throw new Exception("Error Zipping Data File : " + proc.StandardError.ReadToEnd());
        }

filetozip is passed as an argument above. The above code does not work properly. I am getting proc.ExitCode=1. Which is the right way to append the file paths.Is string filetozip = file1+ "\"" + file2+" "; the right way? I can have one or more files. What is the separator used?

Jeevika
  • 155
  • 1
  • 4
  • 18

1 Answers1

3

The command line that you want to create looks like

enter image description here

plus the required switches (arguments quoted and space delimited).

String.Join or StringBuilder are some coding things that may be helpful

xmojmr
  • 8,073
  • 5
  • 31
  • 54