Jump to content

help with batchfile running on certain days


Recommended Posts

Hi all,

anyone help me on this i want on certain days to run diffrent .bat files I have this but its not working... Im sorry im new to creating batch files anyone help me???

@ECHO OFF

:LOOP

ECHO Waiting for 5 minutes...

PING -n 300 127.0.0.1>nul

IF %DATE:~0,3%==Mon CALL monbreakfast-rename.bat

IF %DATE:~0,3%==Tue CALL tuesbreakfast-rename.bat

IF %DATE:~0,3%==Wed CALL wedbreakfast-rename.bat

IF %DATE:~0,3%==Thu CALL thursbreakfast-rename.bat

IF %DATE:~0,3%==Fri CALL fribreakfast-rename.bat

IF %DATE:~0,3%==Sat CALL satbreakfast-rename.bat

IF %DATE:~0,3%==Sun CALL sunbreakfast-rename.bat

Link to comment
Share on other sites


Can you post the output of (in a command window)

ECHO %DATE%

[ENTER]

Then post the output of

DATE

[ENTER]

and

DATE /T

[ENTER]

and

Echo.|Command /C Date

[ENTER]

? :unsure:

AND read this :

http://www.robvanderwoude.com/datetime.php

(and pages linked to, expecially these):

http://www.robvanderwoude.com/datetimentmath.php

before posting the said info. ;)

Which OS are you running?

Check these, too ;):

http://support.mogware.net/index.php?topic=930.0

http://www.computing.net/answers/windows-x...eek/152202.html

jaclaz

Edited by jaclaz
Link to comment
Share on other sites

my output on date is

Current date is Mon 11/01/2010

how can i parse mon in dos??

It's really DOS?

Or is it Command Prompt of a NT based system?

Like 2K, XP or Vista or 7?

The answer is however already in the given links, have you checked them (hint: last one may do if not "pure" DOS ;))

jaclaz

Link to comment
Share on other sites

ok ignore that, im on xp and i cant work out how to get the date command to show me todays Day so i can parse it.

@For /F "tokens=2,3,4 delims=/ " %%A in ('Date /t') do @(

set Day=%%a

set month=%%b

Set year=%%C

)

if %DAY%==Mon goto :mon

if %DAY%==Tue goto :tue

if %DAY%==Wed goto :wed

if %DAY%==Thu goto :thu

if %DAY%==Fri goto :fri

if %DAY%==Sat goto :sat

if %DAY%==Sun goto :sun

Now i know the date /t command dont show the day (mon) but doing Echo.|Command /C Date

does show at day(mon) how can i parse that command?

Sorry for being a noob I am learning, takes some time

Link to comment
Share on other sites

If you wanted to try a vbs script, I have it so echo out the day Name.

This could be modified to do what you want it to.

Dim MyDate :MyDate = WeekdayName(Weekday(Now))
Select Case MyDate
Case "Monday"
WScript.Echo "Today Is : " & MyDate
Case "Tuesday"
WScript.Echo "Today Is : " & MyDate
Case "Wednesday"
WScript.Echo "Today Is : " & MyDate
Case "Thursday"
WScript.Echo "Today Is : " & MyDate
Case "Friday"
WScript.Echo "Today Is : " & MyDate
Case "Saturday"
WScript.Echo "Today Is : " & MyDate
Case "Sunday"
WScript.Echo "Today Is : " & MyDate
End Select

Here is what you wanted a way to run bat on certain days

Save as RunBat.vbs

 Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim MyDate :MyDate = WeekdayName(Weekday(Now))
Select Case MyDate
Case "Monday"
Act.Run("Cmd /C monbreakfast-rename.bat"),1,True
Case "Tuesday"
Act.Run("Cmd /C tuesbreakfast-rename.bat"),1,True
Case "Wednesday"
Act.Run("Cmd /C wedbreakfast-rename.bat"),1,True
Case "Thursday"
Act.Run("Cmd /C thursbreakfast-rename.bat"),1,True
Case "Friday"
Act.Run("Cmd /C fribreakfast-rename.bat"),1,True
Case "Saturday"
Act.Run("Cmd /C satbreakfast-rename.bat"),1,True
Case "Sunday"
Act.Run("Cmd /C sunbreakfast-rename.bat"),1,True
End Select

This one I added a check to make sure the file exists before it ran

Save As RunBatch.vbs

 Dim Act :Set Act = CreateObject("Wscript.Shell")
Dim Fso :Set Fso = CreateObject("Scripting.FileSystemObject")
Dim MyDate :MyDate = WeekdayName(Weekday(Now))
Dim CmdRun
Select Case MyDate
Case "Monday" : CmdRun = "monbreakfast"
Case "Tuesday" : CmdRun = "tuesbreakfast"
Case "Wednesday" : CmdRun = "wedbreakfast"
Case "Thursday" : CmdRun = "thursbreakfast"
Case "Friday" : CmdRun = "fribreakfast"
Case "Saturday" : CmdRun = "satbreakfastt"
Case "Sunday" : CmdRun = "sunbreakfast"
End Select
CmdRun = Act.CurrentDirectory & "\" & CmdRun & "-rename.bat"
If Fso.FileExists(CmdRun) Then
Act.Run("Cmd /C " & Chr(34) & CmdRun & Chr(34)),1,True
Else
MsgBox "ERROR : Can Not Find This File" & vbCrLf & CmdRun,4128,"Missing File Error"
End If

Link to comment
Share on other sites

Now i know the date /t command dont show the day (mon) but doing Echo.|Command /C Date

does show at day(mon) how can i parse that command?

Sorry for being a noob I am learning, takes some time

Well, the parsing approach with a FOR seems allright to me.

What happens if on Command Line, NOT in a batch you issue:

FOR /F "tokens=4" %A IN ('Echo.^|Command /C Date') DO ECHO %A

(you should be able to copy and paste the above on command line.

If you get the "mon" (BTW:you know your clock/calendar is 4 days late, don't you?)

Try this:

@FOR /F "tokens=1,4" %A IN ('Echo.^|Command /C Date') DO @IF %A.==Current. SET %A=%B&SET %A

Read how for tokens/delimiters work:

http://www.robvanderwoude.com/ntfortokens.php

:hello:

jaclaz

Link to comment
Share on other sites

To try to help you with the parsing, as already requested by jaclaz, we really do need to see some output.

For example, what is echo'd to the screen if you enter this at the 'command prompt'?

For %# In ("%Date%") Do @Echo/[%~#]

As a side note, you could use WMIC in a batch file.

@Echo off & Setlocal
Set "_=mon tues wed thurs fri sat sun"
For /f %%# In ('WMIC Path Win32_LocalTime Get DayOfWeek^|Findstr [1-7]') Do (
Set DOW=%%#)
For /f "tokens=%DOW%" %%# In ("%_%") Do Call %%#breakfast-rename.bat

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...