A PLAIN BATCH SCRIPT TO CREATE A 7Z ARCHIVE OF A SPECIFIED FOLDER WITH THE CURRENT DATE IN THE NAME

UPDATED ON: 2025-05-06
Today is the lazy monday, so nothing complex at this time.
Just a simple backup procedure of copying the appointed folder to a specific place in a 7z archive
with a current date name with archive validation upon completion.
To make things rollin’ of course you should have 7z software installed on your `puter.
@echo off
setlocal enableextensions enableddelayeexpansion
set "source=C:\Projects"
set "dest=E:\Backups"
:: splitting %DATE% into MM/DD/YYYY parts, this part was a bitch to implement
for /F "tokens=1-3 delims=/." %%A in ("%DATE%") do (
set month=%%B
set day=%%A
set year=%%C
)
:: converting date stamp to YYYY-MM-DD
set "formatted_date=%year%-%month%-%day%"
:: final name
set "archive_name=projects-%formatted_date%.7z"
:: backing things up
"%ProgramFiles%\7-Zip\7z.exe" a -t7z "%dest%\%archive_name%" "%source%\*"
if errorlevel 1 goto :err_create_archive
:: integrigty check
"%ProgramFiles%\7-Zip\7z.exe" t "%dest%\%archive_name%"
if errorlevel 1 goto :err_test_archive
goto :end_script
:err_create_archive
echo Error while creating archive!
goto :end_script
:err_test_archive
echo Integrity check failed! Archive is corrupted.
goto :end_script
:end_script
endlocal
exit /b
Batch script overwrites existing archive, so one archive per day is possible
[it is sufficient for my needs and matches my workflow]