Windows CMD file/folder Compression using 7z or alternative .tar.gz


I've searched how to compress files/folders using 7z on windows cmd, I've found the way to compress to: zip, tar, 7z, ..etc but not .tar.gz or .tar.bz2

Here it is the documentation I user:

And here is the command I used:

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a -t7z "%%X.7z" "%%X\"

Change "7z" in both "%%X.7z" "-t7z" to the required extension, and you're ready to get the desired result. But unfortunately this way not applicable to .tar.gz

I need to use gzip compression & don't know how, of course on CMD. Any way? I'm sure there's a way using 7z bot how? If there's alternatives it's OK..

Best Solution

Solved. You can accomplish this by writing a CMD batch file with the following contents:

for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a -ttar "%%X.tar" "%%X\"
for %%X in (*.tar) do "c:\Program Files\7-Zip\7z.exe" a -tgzip "%%X.gz" "%%X"

Note that the double % signs should be removed if you're trying to directly execute this within an interactive CMD console.