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.

  • Uhmm, write a batch file that uses 7-zip? What have you tired already? Where are you getting stuck? – Ƭᴇcʜιᴇ007 Sep 15 '13 at 18:02

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.

  • How would I augment this to perform on both .rar and .zip? – Ovaryraptor Oct 10 '18 at 21:35
  • Also, would it be possible to add a command to then delete the previous file? – Ovaryraptor Oct 10 '18 at 21:46
  • @Ovaryraptor just replace (*.zip) with (*.rar) and run that version too. As for deleting, I wouldn't recommend doing it in this script for safety. Unless you have backups, you might lose the files if they don't get converted, since this script doesn't have any error handling. Just check if you have the same number of new and old archives by sorting by date and selecting the newly created archives and comparing the number to total files in folder (minus the batch script file). – user1306322 Aug 24 at 19:07

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 )

  • I'm still struggling to make this work for me. – user1306322 Sep 15 '13 at 19:26
  • What problem are you having? The above snippet assumes your .zip files are in the 7-zip program directory. You should run that command from an elevated command prompt. – Clint Priest Sep 15 '13 at 19:47
  • Alternatively put your zips in an unprotected directory, replace the 7z.exe references with the full path to the 7z.exe. Then from a regular cmd prompt cd into the dir with your zip files and run the modified snippet. – Clint Priest Sep 15 '13 at 19:49
  • I just did it and it compresses the files in the folder the bat file is being run from (1 test zip archive and the bat file itself). After which it says 2 times "cannot find specified file". – user1306322 Sep 15 '13 at 19:53
  • Well, I tried for %%F in (*.zip) do ( "C:\Program Files\7-Zip\7z.exe" e -y -o%%~nF.tmp %%F * ) and it says cannot find archive for all zip files in folder. – user1306322 Sep 15 '13 at 20:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.