title: Zipping multiple files into multiple zip files with batch script
body: <p>I need to get a batch script running that takes a source folder and zips every file into its own zip file recursively through all subfolders and save the zip files to a given destination.</p>
  
  <p>Here is a working variant that just takes the source folder zips it and saves the zip to the destination:</p>
  
  <pre><code> @echo off
  
  
   set year=%date:~-4,4%
   set month=%date:~-10,2%
   set day=%date:~-7,2%
   set hour=%time:~-11,2%
   set hour=%hour: =0%
   set min=%time:~-8,2%
  
   set zipfilename=%~n1.%year%_%month%_%day%_%hour%_%min%
   set destination=%~dp1
  
   set source="%~1\*"
   set destpath="%~2"
   set destname="%~3"
   set ziptyp="%~4"
   set dest= "%destpath%\%destname%_%year%_%month%_%day%_%hour%_%min%.%ziptyp%"
   REM "%destination%Backups\%zipfilename%.%desttyp%"
  
   IF [%1]==[/?] GOTO BLANK
   IF [%1]==[] GOTO BLANK
   IF [%1]==[/h] GOTO BLANK
   IF [%1]==[?] GOTO BLANK
  
   set AppExePath="%ProgramFiles(x86)%\7-Zip\7z.exe"
   if not exist %AppExePath% set AppExePath="%ProgramFiles%\7-Zip\7z.exe"
  
   if not exist %AppExePath% goto notInstalled
  
   echo Backing up %source% to %dest%
  
  
   if /I %ziptyp%=="zip" ( 
   %AppExePath% a -rtzip %dest% %source%)
  
   if /I %ziptyp%=="7z" ( 
   %AppExePath% a -rt7z %dest% %source%)
  
  
   echo %source% backed up to %dest% is complete!
  
   goto end
  
   :BLANK
  
  
   goto end
  
   :notInstalled
  
   echo Can not find 7-Zip
  
  
   :end
  </code></pre>
  
  <p>For this one I need to change the following parts:</p>
  
  <pre><code> if /I %ziptyp%=="zip"
  </code></pre>
  
  <p>and 
       if /I %ziptyp%=="7z"</p>
  
  <p>I tried the following ways and more:</p>
  
  <pre><code> (
   cd  %source%
   FORFILES %source% /M *.* /C "%AppExePath% a -rtzip "%%~nG.zip" ".\%%G\*"")
  </code></pre>
  
  <p>or</p>
  
  <pre><code> FOR /R %source% %%G in (.) do ( 
   Pushd %%G 
   %AppExePath% a -rtzip "%%~nG.zip" ".\%%G\*"
   Popd )
  </code></pre>
  
  <p>or</p>
  
  <pre><code> for /R %%a in (%source%) do (zip -r -p "%%~na.zip" ".\%%a\*")
  </code></pre>
  
  <p>Does anyone have an idea on how to get this working?</p>
  
  <p>Thanks in advance,</p>
  
  <p>TheVagabond</p>