7z to compress folders

I am trying to make a zip / 7z folder using the 7zG.exe command line. The code I use for files, but not for folders. Can someone please show me the correct path using the 7z command line to compress folders? Here is an example of code that only works for files. Whenever I try to run this code, 7zip displays a message with the message "Invalid Parameter"

string sourceName = "Folder\Folder1";
string targetName = "Example.gz";

// 1
// Initialize process information.
//
ProcessStartInfo p = new ProcessStartInfo();
p.FileName = "7zG.exe";

// 2
// Use 7-zip
// specify a=archive and -tgzip=gzip
// and then target file in quotes followed by source file in quotes
//
p.Arguments = "a -tgzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
p.WindowStyle = ProcessWindowStyle.Hidden;

// 3.
// Start process and wait for it to exit
//
Process x = Process.Start(p);
x.WaitForExit();
+4
source share
3 answers

as indicated in the comments section, you should use 7za.exe

This link gives you a complete example string

Your code will look like this:

string sourceName = "Folder\Folder1";
string targetName = "Example.gz";

ProcessStartInfo p = new ProcessStartInfo();
//first change
p.FileName = "7za.exe"; 
//second change
p.Arguments = "a -tzip \"" + targetName + "\" \"" + sourceName + "\" -mx=9"; 
p.WindowStyle = ProcessWindowStyle.Hidden;
Process x = Process.Start(p);
x.WaitForExit();
+8
source

gzip, bzip2 (, , ..).

tar ( ), ( , Unix) tar.gz tar.bz2.

-tzip -t7zip :

p.Arguments = "a -t7z \"" + targetName + "\" \"" + sourceName + "\" -mx=9";

, 7za.exe 7zG.exe, GUI, - 7zip ( - dll), 7zip:

7z.exe - 7-Zip. 7z.exe 7z.dll 7-Zip. 7z.dll 7-Zip File Manager.

7za.exe(a = alone) 7-Zip. 7za.exe 7z, lzma, cab, zip, gzip, bzip2, Z tar. 7za.exe .

7za.exe , , 9.22 7z922_extra.7z (link).

+5

try this command:

7za  -tzip <archive-name> <folder-name>
0
source

All Articles