Forum Home
Press F1
 
Thread ID: 34992 2003-06-29 22:12:00 Batch Programming with Date and Subst Kame (312) Press F1
Post ID Timestamp Content User
156207 2003-06-29 22:12:00 I am trying to create a batch program that loads a certain command depending on the day (usually end of the month).

I currently use

SUBST B: E:\Daily

which sets the CDROMs directory called Daily as B: but I would like to change this by whenever a certain day (end of the month) I would like it to use a different command like SUBST B: E:\<thatmonth>

I load this Batch file on startup, it shouldn't require user input, although this can be fixed by using echo.|<command> for anything that requires enter.

Any help on this would be appreciated.


Cheers

KK
Kame (312)
156208 2003-06-29 23:49:00 Are you any good at C? Its smarter than DOS batch files (or is it NT batch files?) Dolby Digital (160)
156209 2003-06-30 00:23:00 I don't think you can set variables from the output of commands in DOS.

I did something similar a while ago. I ended up writing a couple of simple C programmes to do the work (they are also much faster, DOS pipes are really slow).

In your case I would write a simple ismonth command and end up with something like (while grumbling about how spoilt bash has made me):


REM find out what month it is
ismonth jan
if not errorlevel 1 goto jan
ismonth feb
if not errorlevel 1 goto feb
...
goto error

:jan
subst d:\jan b:
goto end
:feb
...

:end


Don't know how slow it would be, esp later in the year (smartdrv is your friend).

You may speed it up by caching the month. Only running the ismonth stuff if the month changes. Based on something like this (homepages.paradise.net.nz).
bmason (508)
156210 2003-06-30 05:53:00 Turbo Pascal does things like this nicely too. You might even be able to do it in Basic. :D

Of course, this is the sort of thing in which the time taken to do the "elegant" programmed solution is hugely greater than the amount of time it takes to do it manually. B-)

Try this: @ECHO OFF
REM EOM.BAT
ECHO Is it the end of the month? If so, do the SUBST E: command
ECHO as listed on page XX of the Computer Instructions book.
ECHO The date today is:
DATE
Graham L (2)
1