Here is the batch code rewritten and extended. The batch file does not immediately stop on failing to compress a subfolder to a ZIP archive.
@echo off
setlocal EnableExtensions DisableDelayedExpansion
rem Get current date in region dependent format with . as delimiter.
set "FileDate=%DATE:/=.%"
set "ErrorCount=0"
set "FolderCount=0"
rem Compress each non hidden subfolder in current folder into a ZIP file.
for /D %%I in (*) do (
set /A FolderCount+=1
"7z.exe" a -r -tzip "%%I.zip" ".\%%I\"
if errorlevel 1 (
echo Failed creating archive: "%%I.zip">>"Error-log %FileDate%.txt"
set /A ErrorCount+=1
) else (
echo Archive "%%I.zip" created succesfully.>>"Archive-log %FileDate%.txt"
)
)
rem Exit batch processing if no subfolder was found in current folder?
if %FolderCount% == 0 endlocal & exit /B
set "ErrorPluralS=s"
if %ErrorCount% == 1 set "ErrorPluralS="
set "FolderPluralS=s"
if %FolderCount% == 1 set "FolderPluralS="
echo Processed %FolderCount% folder%FolderPluralS% with %ErrorCount% error%ErrorPluralS%.>>"Archive-log %FileDate%.txt"
endlocal
if errorlevel 1
working also without usage of delayed expansion means:
IF the exit code of the previous command or executable is greater or equal 1 THEN ...
This is explained in the Microsoft support article Testing for a Specific Error Level in Batch Files and working from MS-DOS to Windows 10 in batch files and on command line.
For understanding the 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 /?
endlocal /?
for /?
if /?
rem /?
set /?
setlocal /?
Read also the answers on: