I'm working with a nested if statement to delete directories if they meet a certain criteria. This is part of a for loop to check all directories in a given location. Variable %JDcalc%
represents the difference between today's julian day and the directory's julian day. Variable %fdate%
is the directory name. The errorlevel is deteremined by the following:
echo.%fdate% | findstr /C:"OE"
This nested if statement works:
if %errorlevel% EQU 0 (if %JDcalc% GEQ 31 (echo DELETE) else (echo KEEP)) else (if %JDcalc% GEQ 14 echo DELETE)
As soon as I switch echo DELETE
to rd %fdate%
the batch script outputs, "The system cannot find the specified file."
if %errorlevel% EQU 0 (if %JDcalc% GEQ 31 (rd %fdate%) else (echo KEEP)) else (if %JDcalc% GEQ 14 rd %fdate%)
If I use a simpler if statement like if %JDcalc% GEQ 14 (rd %fdate%)
it works fine.
EDIT: Below is the script in question.
@echo off
cd /d C:\Batch\Maximus\Dailies
:TODAYS_JULIAN_DAY
set /a JD=2458939
::a calculation that determines this number is usually here
::above is the julian day for 3.30.2020
:FOR_LOOP_FOLDER_NAME
for /f "delims=" %%a in ('dir /a:d /b') do (
SETLOCAL EnableDelayedExpansion
set fdate=%%a
::fdate is set to the date in the directory name
::with a naming convention of yymmdd
call :SUBROUTINE
ENDLOCAL
)
GOTO END_BATCH
:SUBROUTINE
set folyy=%fdate:~0,2%
set folmm=%fdate:~2,2%
set foldd=%fdate:~4,2%
set /a "folyy=1000020%folyy% %%10000,folmm=100%folmm% %% 100,foldd=100%foldd% %% 100"
set /a folJD=foldd-32075+1461*(folyy+4800+(folmm-14)/12)/4+367*(folmm-2-(folmm-14)/12*12)/12-3*((folyy+4900+(folmm-14)/12)/100)/4
set /a JDcalc=JD-folJD
echo.%fdate% | findstr /C:"OE"
if %errorlevel% EQU 0 (if %JDcalc% GEQ 31 (rd %fdate%) else (echo KEEP)) else (if %JDcalc% GEQ 14 rd %fdate%)
GOTO :eof
:END_BATCH
ENDLOCAL