Search code examples
batch-filecmdwindowzipwinrar

Zipping all files and subdirectories inside a folder using batch file


I wrote the below script to zip all the files and sub directories inside a folder. But I am only getting the sub directories zipped. What am I doing wrong here? Please advice.

FOR /D %%i IN ("*") DO "C:\Program Files (x86)\WinRAR\WinRAR.exe" a ../../../apps-1.0.2.zip "%%~fi\"

Solution

  • Give a try for this example and tell me the results :

    -R Switch : for recurring subfolders

    -AF<Type> Switch : specify the archive format

    -EP1 Switch : to exclude the names of the basic folder

    -DH Switch: open shared files : Can process files opened by other applications. This switch is useful if an application allows access the file read, but if all access is prohibited, the file open always fail.

    @echo off
    Set Winrar=%ProgramFiles%\WinRAR\WinRAR.exe
    Set MyFolder=%USERPROFILE%\Favorites
    Set ArchiveName=apps-1.0.2.zip
    "%Winrar%" a -r -afzip -ep1 -dh "%ArchiveName%" "%MyFolder%"
    pause
    

    Edit on 29/06/2016 @13:30

    For others switchs and commands you can execute this batch to open the help file of Winrar :

    @echo off
    Set WinrarHelp=%ProgramFiles%\WinRAR\WinRAR.chm
    Start "" "%WinrarHelp%"