Great job. Thanks for sharing this. I have used your code to improve my own incremental backup script. Our two scripts now differ only in the following way:
1. In addition to folder exclusion, I also exclude certain files; e.g., I use the following:
set EXF=thumbs.db ethumbs.db desktop.ini *.tmp *.hdmp *.blf {* .DS_Store ._DS_Store
Then amend the robocopy command lines with:
/XF %EXF%
2. I include a call to a separate batch file that creates environmental variables for time and date parameters:
CALL DateTimeFunctions
This makes the routine international. (Your script as is will fail in Europe, for example.)
It also keeps my backup script concise, since I use this same date-time batch for other purposes.
I've included my version of DateTimeFunctions.bat below, which includes references to the original author and some testing code at the end. It may be necessary to add SETLOCAL and ENDLOCAL to the top and bottom of the final script, and make minor adjustments
to variable names.
Thanks again.
@echo off
:: http://www.computerhope.com/forum/index.php?topic=76081.msg497599#msg497599
:: http://www.computerhope.com/forum/index.php?topic=72945.0
:: Code published in the above two pages has been combined
set vbsfile=newdate.vbs
echo Newdate = (Date())>%vbsfile%
echo DateYear = DatePart("YYYY", Newdate)>>%vbsfile%
echo DateMonth = DatePart("M" , Newdate)>>%vbsfile%
echo DateDay = DatePart("D" , Newdate)>>%vbsfile%
echo WeekOfYear = DatePart("WW" , Newdate)>>%vbsfile%
echo DayOfYear = DatePart("Y" , Newdate)>>%vbsfile%
echo WeekDayNumber = DatePart("W" , Newdate)>>%vbsfile%
echo TodayNameShort = WeekdayName(WeekDayNumber,True)>>%vbsfile%
echo TodayNameFull = WeekdayName(WeekDayNumber,False)>>%vbsfile%
echo MonthNameShort = MonthName(DateMonth,True)>>%vbsfile%
echo MonthNameLong = MonthName(DateMonth,False)>>%vbsfile%
echo TimeHour = Hour(Time)>>%vbsfile%
echo TimeMinute = Minute(Time)>>%vbsfile%
echo TimeSecond = Second(Time)>>%vbsfile%
echo If TimeHour^<12 Then>>%vbsfile%
echo AMorPM="AM">>%vbsfile%
echo Else>>%vbsfile%
echo AMorPM="PM">>%vbsfile%
echo End If>>%vbsfile%
echo Wscript.Echo DateYear^&" "^&DateMonth^&" "^&DateDay^&" "^&Week^
OfYear^&" "^&DayOfYear^&" "^&WeekDayNumber^&" "^&Today^
NameShort^&" "^&TodayNameFull^&" "^&MonthNameShort^&" "^&MonthNameLong^&" "^&TimeHour^&" "^&Time^
Minute^&" "^&TimeSecond^&" "^&AMorPM>>%vbsfile%
for /f "tokens=1-14 delims= " %%A in ('cscript //nologo %vbsfile%') do (
set Year=%%A
set Month=%%B
set Day=%%C
set WeekNumber=%%D
set DayNumber=%%E
set DayOfWeekNum=%%F
set DayNameShort=%%G
set DayNameLong=%%H
set MonthNameShort=%%I
set MonthNameLong=%%J
set TimeHour=%%K
set TimeMinute=%%L
set TimeSecond=%%M
set TimeAMPM=%%N
)
::----- ADJUST VALUES LESS THAN 10
IF %Day% LEQ 9 SET Day=0%Day%
IF %Month% LEQ 9 SET Month=0%Month%
IF %TimeHour% LEQ 9 SET TimeHour=0%TimeHour%
IF %TimeMinute% LEQ 9 SET TimeMinute=0%TimeMinute%
IF %TimeSecond% LEQ 9 SET TimeSecond=0%TimeSecond%
GOTO :EOF
echo.
echo Date Year : %Year%
echo Date Month : %Month%
echo Date Day : %Day%
echo Week Of Year : %WeekNumber%
echo Day Of Year : %DayNumber%
echo Day Of Week [Number] : %DayOfWeekNum%
echo Day Of Week [Short Name] : %DayNameShort%
echo Day Of Week [Full Name] : %DayNameLong%
echo Month [Short Name] : %MonthNameShort%
echo Month [Long Name] : %MonthNameLong%
echo Time Hour : %TimeHour%
echo Time Minute : %TimeMinute%
echo Time Second : %TimeSecond%
echo.
echo %DayNameLong%, %MonthNameLong% %Day%, %Year% is in week %WeekNumber%
echo.
pause