Is this possible with a batch file?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
hendrikbez
Posts: 20
Joined: 11 Sep 2008 22:36

Is this possible with a batch file?

#1 Post by hendrikbez » 26 Mar 2012 23:44

I have a bat file one for every day that runs, with system scheduler, so for each bat file I have to run system scheduler.
Is there a way that I can only run system scheduler one. but the bat file give the day.


Eg
Here is Day 1 (Busres 1(Mon).bat)

@echo off
net use K: \\000.00.0.00\osback
:: [To Connect(map) K: drive with ip]
cd\
echo off
K:
cd \
Xcopy . /D /I /F /E /Y D:\Backup\Busres\1Mon
net use K: /delete /y
:: [To disconnect the K: Drive]
exit



Here is day 2 Busres 2(Tue).bat

@echo off
net use K: \\000.00.0.00\osback
:: [To Connect(map) K: drive with ip]
cd\
echo off
K:
cd \
Xcopy . /D /I /F /E /Y D:\Backup\Busres\2Tue
net use K: /delete /y
:: [To disconnect the K: Drive]
exit


Can I make one batch file so that it can run on day 1,2,3,4,5,6 and 7.

Thank You
Last edited by hendrikbez on 27 Mar 2012 00:58, edited 1 time in total.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Is this possible with a batch file?

#2 Post by foxidrive » 27 Mar 2012 00:06

Yes it is possible but it is specific to your locale and regional settings

When I echo the %date% variable I get this:

Code: Select all

D:\>echo %date%
Tue 27/03/2012


so I can set a variable to the first token in the %date% variable

Code: Select all

@echo off
for /f "tokens=1" %%a in ("%date%") do set day=%%a
echo %day%


With some extra logic you can add a number from 1 to 7

aGerman
Expert
Posts: 4743
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Is this possible with a batch file?

#3 Post by aGerman » 27 Mar 2012 15:31

Have a look at the DateToDOW function.

Regards
aGerman

Post Reply