Batch repacking zip archives into 7z

I have many zip archive files that I would like to re-pack into 7z archive format, as that would save me a lot of space. How do I batch-repack those files on a Windows 7 computer?

I tried doing this via GUI version of 7-zip archiver, but I didn't find a corresponding function. WinRar has a "Convert" functionality, but it doesn't archive into 7z format.

I'm not asking exclusively for a solution involving Batch-file scripting.

1

4 Answers

This is my own take on the problem:

for %%F in (*.zip) do ( "C:\Program Files\7-Zip\7z.exe" x -y -o"%%F_tmp" "%%F" * & pushd %%F_tmp & "C:\Program Files\7-Zip\7z.exe" a -y -r -t7z ..\"%%~nF".7z * & popd & rmdir /s /q "%%F_tmp" )

Save this to a zip to 7z.bat file, place it into the directory with all the zip files you want to convert and double-click it there.

Thanks to Clint Priest for the base code.

3

You can use the 7zip command line (detailed examples here) to first extract all files/folders (using the e command) and then re-compress them to 7z (using the a command).

If you plan on repeating this operation, consider capturing the command lines in a .bat/.cmd file.

And always test on a small directory before trying on a huge number of archives!

Here is a command line that will do it for you, this assumes that the zip files are in the same directory as 7z.exe:

for %F in (*.zip) do ( 7z.exe e -y -o%~nF.tmp %F * & pushd %~nF.tmp & ..\7z.exe a -y -r -t7z ..\%~nF * & popd & rmdir /s /q %~nF.tmp )

7

user1306322 answer was super helpful for me, thanks!! I just wanted to convert from rar to zip so I changed the extensions and it worked lke a charm

for %%F in (*.rar) do ( "C:\Program Files\7-Zip\7z.exe" x -y -o"%%F_tmp" "%%F" * & pushd %%F_tmp & "C:\Program Files\7-Zip\7z.exe" a -y -r -tzip ..\"%%~nF".zip * & popd & rmdir /s /q "%%F_tmp" )

And then I wanted to delete the files, they said in the convo that it is better not to in case something can't be converted because it would be deleted and lost, but I had to do this many times (Many folders with diferents mangas) so deleting them afterwards was a lot of work and I preferred to take the risk I added a line below like this

del *.rar

And that's it, everything done! The only thing is that I have to go folder by folder and execute the scripts, I wonder if I could add something to just run it in the parent Manga directory and it would do the trick in all subfolders...

Anyways I just want to comment that I did this to convert the files from .cbr to .cbz, so the final code is what user1306322 did plus a renaming line before and afterwards

ren *.cbr *.rar
for %%F in (*.rar) do ( "C:\Program Files\7-Zip\7z.exe" x -y -o"%%F_tmp" "%%F" * & pushd %%F_tmp & "C:\Program Files\7-Zip\7z.exe" a -y -r -tzip ..\"%%~nF".zip * & popd & rmdir /s /q "%%F_tmp" )
ren *.zip *.cbz
del *.rar

So if anyone is reading this and doesn't know how to code like me, these are the instructions to batch convert cbr to cbz: First install 7zip, then just create a text file (.txt) in the folder you have the files to be converted, open it and paste the code just above inside, save and close and then rename the extension ".txt" to ".bat", something like "cbr to cbz.bat". Double click this "cbr to cbz.bat" file and voilà!

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like