Search code examples
zipwinrar

How to add files/folders to multiple zip files at once with WinRAR?


Is there any way to add files/folders to multiple zip files at once. For example:

Updates:

folder1
folder2
file1
file2

Archives:

archive1.zip
archive2.zip
archive3.zip

I need to add updates to all archives without opening all of them and pasting updates in there.

Any way to do this?

Or is there another archive program that can do this?


Solution

  • This can be done using a batch file and for example WinRAR.

    @echo off
    if not exist archive*.zip (
        echo There are no archive*.zip files to update in
        echo.
        echo %CD%
        echo.
        pause
        goto :EOF
    )
    set "ErrorCount=0"
    for %%I in (archive*.zip) do (
        "%ProgramFiles%\WinRAR\WinRar.exe" u -afzip -cfg- -ep1 -ibck -inul -r -y "%%I" folder1 folder2 file1 file2
        if errorlevel 1 (
            echo Error on updating %%I
            set /A ErrorCount+=1
        )
    )
    if not "%ErrorCount%" == "0" (
        echo.
        pause
    )
    set "ErrorCount="
    

    For each archive*.zip file WinRAR is called to update the ZIP file with the two folders and the two files.

    The batch processing finishes without printing any message and without pausing if all ZIP files found could be updated successfully. Otherwise the batch file outputs which ZIP file could not be updated for example because of read-only attribute set, and pauses the batch processing before finishing so that the user can read the error message(s).

    For details on the WinRAR command u and the used switches open in WinRAR from menu Help the Help topics, open on tab Contents the item Command line mode and read at least the help pages:

    • Command line syntax
    • Commands - Alphabetic commands list
    • Switches - Alphabetic switches list

    For understanding the other used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.

    • echo /?
    • for /?
    • goto /?
    • if /?
    • pause /?
    • set /?