Trouble with batch file

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Trouble with batch file

Post by ErikJan »

I want to recompress tar.gz files to 7z (the contents of the tar, not the tar itself). As there are no real solutions I could find (yet - there's PeaZIP but there first all files are uncompressed, then re-compressed and only then are files deleted), I thought I'd write a simple bat/cmd file.

The file should process all tar.gz files in the folder of the batch file (no subfolders needed). Unpack the tar and then save the tar-contents into a folder with the base-name of the file. 7zip can do that in one step, something like (I still would need to provide the extract folder): 7z x %1 -so | 7z x -si -ttar.

All my files have the following name YYYYMMDD.tar.gz, so the base-name is simply getting the left 8 characters (the script would struggle with the double extension anyway).

I can loop the files like this: for %%i in (*.tar.gz) do

And then I need to add the compress step of course. I tried for a while but I get stuck with %% and ~ all the time :(.

Anyone who can give me a kick start here please?

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Trouble with batch file

Post by ErikJan »

I found something that might help here: https://aarmstrong.org/tutorials/mass-z ... batch-file" onclick="window.open(this.href);return false;

User avatar
John Gray
PlatinumLounger
Posts: 5401
Joined: 24 Jan 2010, 08:33
Location: A cathedral city in England

Re: Trouble with batch file

Post by John Gray »

Following that link, have you solved your problem?
The syntax of 7Zip can be somewhat idiosyncratic!
John Gray

Venison is quiet deer, and quite dear.

User avatar
ErikJan
5StarLounger
Posts: 1185
Joined: 03 Feb 2010, 19:59
Location: Terneuzen, the Netherlands

Re: Trouble with batch file

Post by ErikJan »

I used 'tar' (available in the latest versions of Win10) tot unpack a tar.gz in one time:

Code: Select all

tar -xzf "%%F" -C !BNam!
This runs in a CMD file (BNam is the target folder, %%F is the tar.gz file)

Then later in my CMD file I create the 7z file

Code: Select all

..\7za a -t7z "..\!BNam!.7z" * -mx=9