stevehubbard Posted January 15, 2010 Share Posted January 15, 2010 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:LOOPECHO 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 More sharing options...
jaclaz Posted January 15, 2010 Share Posted January 15, 2010 (edited) Can you post the output of (in a command window)ECHO %DATE%[ENTER]Then post the output ofDATE[ENTER]and DATE /T[ENTER]andEcho.|Command /C Date[ENTER]? AND read this :http://www.robvanderwoude.com/datetime.php(and pages linked to, expecially these):http://www.robvanderwoude.com/datetimentmath.phpbefore posting the said info. Which OS are you running?Check these, too :http://support.mogware.net/index.php?topic=930.0http://www.computing.net/answers/windows-x...eek/152202.htmljaclaz Edited January 15, 2010 by jaclaz Link to comment Share on other sites More sharing options...
stevehubbard Posted January 15, 2010 Author Share Posted January 15, 2010 my output on date is Current date is Mon 11/01/2010how can i parse mon in dos?? Link to comment Share on other sites More sharing options...
jaclaz Posted January 15, 2010 Share Posted January 15, 2010 my output on date is Current date is Mon 11/01/2010how 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 More sharing options...
stevehubbard Posted January 15, 2010 Author Share Posted January 15, 2010 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=%%aset month=%%bSet year=%%C)if %DAY%==Mon goto :monif %DAY%==Tue goto :tueif %DAY%==Wed goto :wedif %DAY%==Thu goto :thuif %DAY%==Fri goto :friif %DAY%==Sat goto :satif %DAY%==Sun goto :sunNow 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 More sharing options...
gunsmokingman Posted January 15, 2010 Share Posted January 15, 2010 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 SelectHere is what you wanted a way to run bat on certain daysSave 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 SelectThis one I added a check to make sure the file exists before it ranSave 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 More sharing options...
jaclaz Posted January 15, 2010 Share Posted January 15, 2010 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 timeWell, 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 %ARead how for tokens/delimiters work:http://www.robvanderwoude.com/ntfortokens.php jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted January 15, 2010 Share Posted January 15, 2010 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 & SetlocalSet "_=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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now