Avatar of elwayisgod
elwayisgodFlag for United States of America asked on

Windows Batch/Dos - Ignore Case

I set a variable %dow%  and it sets it in this case Mon, Tue, Wed, Thu, Fri, Sat, Sun.  However just in case it ever sets it as MON, for example I need the following batch to handle it correctly and not take into account the case:

REM Now determine which folder to delete in the 'Weekly' location so only last 3 days backup are retained
IF %dow% /i == Sun GOTO SUNDAY >> %ess_bkup_log_file% 2>&1
IF %dow% /i == Mon GOTO MONDAY >> %ess_bkup_log_file% 2>&1
IF %dow% /i == Tue GOTO TUESDAY >> %ess_bkup_log_file% 2>&1
IF %dow% /i == Wed GOTO WEDNESDAY >> %ess_bkup_log_file% 2>&1
IF %dow% /i == Thu GOTO THURSDAY >> %ess_bkup_log_file% 2>&1
IF %dow% /i == Fri GOTO FRIDAY >> %ess_bkup_log_file% 2>&1
IF %dow% /i == Sat GOTO SATURDAY >> %ess_bkup_log_file% 2>&1

:SUNDAY
rmdir %rmdir_weekly%\THU /s /q >> %ess_bkup_log_file% 2>&1
GOTO END

:MONDAY
rmdir %rmdir_weekly%\FRI /s /q >> %ess_bkup_log_file% 2>&1
GOTO END

:TUESDAY
rmdir %rmdir_weekly%\SAT /s /q >> %ess_bkup_log_file% 2>&1
GOTO END

:WEDNESDAY
rmdir %rmdir_weekly%\SUN /s /q >> %ess_bkup_log_file% 2>&1
GOTO END

:THURSDAY
rmdir %rmdir_weekly%\MON /s /q >> %ess_bkup_log_file% 2>&1
GOTO END

:FRIDAY
rmdir %rmdir_weekly%\TUE /s /q >> %ess_bkup_log_file% 2>&1
GOTO END

:SATURDAY
rmdir %rmdir_weekly%\WED /s /q >> %ess_bkup_log_file% 2>&1
GOTO END


:END
Windows BatchMicrosoft DOSWindows 2000

Avatar of undefined
Last Comment
sirbounty

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
sirbounty

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
sirbounty

Hmm - looking at this again, why not do simply:

rmdir %rmdir_weekly%\%dow%/s /q >> %ess_bkup_log_file% 2>&1
ASKER
elwayisgod

Jackpot....
sirbounty

Happy to help - but does the last modification greatly reduce the size of your script?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER
elwayisgod

If %dow% is 'mon' then it needs to delete the 'fri' folder.... Then 'tue' delete 'sat' etc.. that way it keeps only the last three days folder.... Is that what your last comment does?
sirbounty

Oic - then disregard...I misread it.
ASKER
elwayisgod

I'm open do suggestions.. It is clunky but it works :)
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
sirbounty

Is this the entire script?

This should condense it by nearly half...
REM Now determine which folder to delete in the 'Weekly' location so only last 3 days backup are retained
IF %dow% /i == Sun DayToDel=THU
IF %dow% /i == Mon DayToDel=FRI
IF %dow% /i == Tue DayToDel=SAT
IF %dow% /i == Wed DayToDel=SUN
IF %dow% /i == Thu DayToDel=MON
IF %dow% /i == Fri DayToDel=TUE
IF %dow% /i == Sat DayToDel=WED
 
rmdir %rmdir_weekly%\%DayToDel% /s /q >> %ess_bkup_log_file% 2>&1

Open in new window