Windows CMD file/folder Compression using 7z or alternative .tar.gz
Solution 1
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.
Solution 2
With 7-Zip 9.20 you can avoid the for loop just adding \ at name ends, this works for me:
set "_dir=%1"
set "_7zexe=c:\<my-7z-dir>\7z.exe"
"%_7zexe%" a -ttar %_dir%.tar %_dir%\
"%_7zexe%" a -tgzip %_dir%.gz %_dir%.tar
Comments
-
Omranic almost 2 years
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: http://www.dotnetperls.com/7-zip-examples
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..
-
Omranic almost 12 yearsI know that .tar.gz is two formats, .tar is uncompressed archive, and the .gz is the compressed. But the question still goes, how to do it?
-
Omranic almost 12 yearsCan you edit this line to do it pelase: for /d %%X in (*) do "c:\Program Files\7-Zip\7z.exe" a -t7z "%%X.7z" "%%X\"
-
Vadzim over 7 yearsThis script iterates over subdirs in current dir and packs them to separate archives.