Batch for day of Week

October 5, 2010 at 17:43:05
Specs: Windows Vista
This isn't really a question.
I was looking for this and your threads from 1999 and 2002 didn't give me what I needed so I've written my own code and through I would share.

I wanted to make a backup of some files and instead of overwriting one copy or keeping many versions by appending date I decided that I wanted the last 7 days of files stored in an appropriately named folder and then overwrite the following week.

Previous code was hard to follow (or just plain didn't work) or required calling another batch that was holding the output of the date and I wanted one file that's easy to follow and I came up with the following code. I like code that is easy to understand, mainly so that when someone else tries to maintain or troubleshoot that it's as easy as possible; probably cos of the PITA when I have to maintain someone else's untidy code.

----------------------------
@Echo Off
Echo -Start Debug info-
Echo %date%
Echo %date:~0,3%
Echo -End Debug info-
If /I %date:~0,3% == Mon Goto Monday
If /I %date:~0,3% == Tue Goto Tuesday
If /I %date:~0,3% == Wed Goto Wednesday
If /I %date:~0,3% == Thu Goto Thursday
If /I %date:~0,3% == Fri Goto Friday
If /I %date:~0,3% == Sat Goto Saturday
If /I %date:~0,3% == Sun Goto Sunday
Goto End

:Monday
Echo Running Monday batch code
Rem >Insert code here for Monday<
Goto End

:Tuesday
Echo Running Tuesday batch code
Rem >Insert code here for Tuesday<
Goto End

:Wednesday
Echo Running Wednesday batch code
Rem >Insert code here for Wednesday<
Goto End

:Thursday
Echo Running Thursday batch code
Rem >Insert code here for Thursday<
Goto End

:Friday
Echo Running Friday batch code
Rem >Insert code here for Friday<
Goto End

:Saturday
Echo Running Saturday batch code
Rem >Insert code here for Saturday<
Goto End

:Sunday
Echo Running Sunday batch code
Rem >Insert code here for Sunday<
Goto End

:End
Rem >Insert post process code for any/all days<
Rem Pause
Echo -Batch Complete-
----------------------------

It might not be the *most* efficient code, but that's not always the aim.
Cheers,
T


See More: Batch for day of Week

Report •


#1
October 5, 2010 at 19:36:52
That's nice. But it has nothing to do with DOS.

==================================================

@echo off
if not %OS%!==! setLocal enableDELAYedeXPansion

::== YMD16.bat

@echo off > d.d

>> d.d echo E 0100 B4 2A CD 21 B4 4C CD 21
>> d.d echo N DAY.COM
>> d.d echo RCX
>> d.d echo 8
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 F0 B4 4C CD 21
>> d.d echo N MONTH.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 89 C8 B4 4C CD 21
>> d.d echo N YEAR.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo E 0100 B4 2A CD 21 88 D0 B4 4C CD 21
>> d.d echo N DAT.COM
>> d.d echo RCX
>> d.d echo A
>> d.d echo W
>> d.d echo Q

debug < d.d > nul
del d.d

dat
for %%a in (1 2 3 4 5 6 7 8 9                                                                  ) do if errorlevel %%a set DD=0%%a
for %%a in (                  10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31) do if errorlevel %%a set DD=%%a
echo Date %DD%

day
if errorlevel 0 set day=Sunday
if errorlevel 1 set day=Monday
if errorlevel 2 set day=Tuesday
if errorlevel 3 set day=Wednesday
if errorlevel 4 set day=Thursday
if errorlevel 5 set day=Friday
if errorlevel 6 set day=Saturday
echo Day %day%

month
for %%a in (1 2 3 4 5 6 7 8 9         ) do if errorlevel %%a set MM=0%%a
for %%a in (                  10 11 12) do if errorlevel %%a set MM=%%a
echo Month %MM%

year
if errorlevel 215 set YYYY=2007
if errorlevel 216 set YYYY=2008
if errorlevel 217 set YYYY=2009
if errorlevel 218 set YYYY=2010
if errorlevel 219 set YYYY=2011
if errorlevel 220 set YYYY=2012
echo Year %YYYY%

set   YYYYMMDD=%YYYY%%MM%%DD%
echo %YYYYMMDD%

del day.com
del month.com
del year.com
del dat.com

::============================ DONE YMD16 ==========================


=====================================
Helping others achieve escape felicity

M2


Report •

#2
October 7, 2010 at 17:45:47
Thanks for the warm welcome. Next time I won't bother.

Report •

#3
October 7, 2010 at 17:51:00
Sorry for being edgy.

I've been doing this long enough to get burned out on non-DOS DOS threads.


=====================================
Helping others achieve escape felicity

M2


Report •

Related Solutions


Ask Question