I need help getting this batch script to work. I am trying to iterate with an IF and GOTO function and it works fine for me until the point where I insert the following code inside the IF.
This is the erro that is presenting Error: ) was unexpected at this time.
CODE I NEED INSIDE THE IF
echo >"%temp%\%~n0.vbs" s=DateAdd("d",%day%,("%date2%")) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
del "%temp%\%~n0.vbs"
set "YYYY=%result:~0,4%"
set "MM=%result:~4,2%"
set "DD=%result:~6,2%"
set "date=%yyyy%%mm%%dd%"
echo %yyyy%
echo %mm%
echo %dd%
echo Export dia %date%
CODE WITHOUT THE IF WHICH WORKS
Set desde=20220420
Set hasta=20220422
:DesdeFormat
set "YYYY=%desde:~0,4%"
set "MM=%desde:~4,2%"
set "DD=%desde:~6,2%"
set "from=%yyyy%-%mm%-%dd%"
echo From= %from%
:HastaFormat
set "YYYY=%hasta:~0,4%"
set "MM=%hasta:~4,2%"
set "DD=%hasta:~6,2%"
set "to=%yyyy%-%mm%-%dd%"
echo To= %to%
echo Fecha de [%from%] hasta [%to%]
echo Wscript.Echo #%to%# - #%from%# >tmp.vbs
for /f %%a in ('cscript /nologo tmp.vbs') do set "total=%%a"
del tmp.vbs
echo ***The Total number of days from %from% until %to% is [%total%]***
echo ****INICIANDO ITERACION****
set /a i=1
echo iteraciones totales:%total% Y el inicio es: %i%
:inicio
IF %i% LEQ %total% (
echo THE CODE/SCRIPT ABOVE SHOULD BE HERE
set /a "i=%i%+1"
::iteracion
echo iteracion: %i%
echo Total: %total%
) else (GOTO :END)
GOTO :inicio
:END
echo EL FIN
pause