gzip
as well as bzip2
are only compression algorithms and cannot be used to compress a file-system structure (e.g. folders, folders with files etc.).
In fact, they are usually preceded by tar
compression (that support folders), to get the famous (in particular in unix-based systems) tar.gz
and tar.bz2
archives.
In your case you can use -tzip
or -t7zip
to directly compress a folder:
p.Arguments = "a -t7z \"" + targetName + "\" \"" + sourceName + "\" -mx=9";
By the way, you should use 7za.exe
instead of 7zG.exe
since the latter is the GUI module, while the former is the command-line standalone version of 7zip (i.e. it does not depend on any other dll), as stated in 7zip manual:
7z.exe is the command line version of 7-Zip. 7z.exe uses 7z.dll from
the 7-Zip package. 7z.dll is used by the 7-Zip File Manager also.
7za.exe (a = alone) is a standalone version of 7-Zip. 7za.exe supports
only 7z, lzma, cab, zip, gzip, bzip2, Z and tar formats. 7za.exe
doesn't use external modules.
You can find 7za.exe
in the extra package, for example for version 9.22 you can find it in the archive called 7z922_extra.7z
(link).