tech-
asked on
VB Script or Batch File to insert date
I need to setup a script that I will execute through Windows Scheduler on a daily basis.
I currently run this command on our Windows 2008 Server:
D:\>robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup04112010.txt
I need the date to automatically 04112010 to update when the script is run. I don't care if it is a VB script or a simple batch file, but it just needs to work so I can automate this process.
Please let me know and Thanks!!!
I currently run this command on our Windows 2008 Server:
D:\>robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup04112010.txt
I need the date to automatically 04112010 to update when the script is run. I don't care if it is a VB script or a simple batch file, but it just needs to work so I can automate this process.
Please let me know and Thanks!!!
Give this a try:
tdate = Right("0" & Month(Now),2) & Right("0" & Day(Now),2) & Year
RunStr = "D:\robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup" & tdate & ".txt"
Set wshell = CreateObject("WScript.Shell")
wshell.Run(RunStr)
Execute the below listed vbscript (.vbs) in your task scheduler
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup" &Date &".txt",0,True
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Depending on the configure format ;) For me it's . (dot)
Below a formated one :P
Below a formated one :P
Set objShell = CreateObject("Wscript.Shell")
objShell.Run "robocopy d: r: /MIR /r:1 /w:1 /log:d:\backup" &Replace(Date,"/","") &".txt",0,True
Yeah I went with extra variable to allow for MMDDYYYY so on months like this its not 4132010 it will always sort well then. Either way it will do what he wants I jsut noticed his current formatting.
ASKER
Thanks!!!
Open in new window