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.
Here is a working variant that just takes the source folder zips it and saves the zip to the destination:
@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
For this one I need to change the following parts:
if /I %ziptyp%=="zip"
and if /I %ziptyp%=="7z"
I tried the following ways and more:
(
cd %source%
FORFILES %source% /M *.* /C "%AppExePath% a -rtzip "%%~nG.zip" ".\%%G\*"")
or
FOR /R %source% %%G in (.) do (
Pushd %%G
%AppExePath% a -rtzip "%%~nG.zip" ".\%%G\*"
Popd )
or
for /R %%a in (%source%) do (zip -r -p "%%~na.zip" ".\%%a\*")
Does anyone have an idea on how to get this working?
Thanks in advance,
TheVagabond