Friday, May 28, 2010

Batch files aplenty

I wrote a tiny batch file a while ago that creates a folder string with the date and time then makes a folder with that string and copies files daily to an external drive for backup purposes. Its grown into a windows event creator and a text file creation with the date and time of start and finish. I thought I would paste them here for anyone to use.

Start of batch file (comment lines are REMmed out to help with creation:

@echo off

REM ****** Run VBS File to create Event log for start of file copy in Information Log ******
cscript "c:\users\reesed\documents\files\evntstrt.vbs"

REM ****** Set FOlder String to current date and time ******
set folder=%date:~10,4%%date:~4,2%%date:~7,2%

REM ****** Make Directory on resource calling folder string ******
mkdir e:\HDDaily\%folder%

REM ****** Create text file in folder string stating copy start ******
echo Start date and time: %date% - %time% >> e:\hddaily\%folder%\cpresult.txt

REM ****** Copy files to resource ******
xcopy \\SERVER LOCATION\*.* e:\HDDaily\%folder% /c /h /e /v /y

REM ****** Append end time and date to text file created in folder string ******
echo End date and time: %date% - %time% >> e:\hddaily\%folder%\cpresult.txt

REM ****** Run VBS file to create event log for end of file copy in Information log ******
cscript "c:\users\reesed\documents\files\evntend.vbs"


Start of VBS FILE (file that creates the event log):

' Constants for type of event log entry
const EVENTLOG_SUCCESS = 0
const EVENTLOG_ERROR = 1
const EVENTLOG_WARNING = 2
const EVENTLOG_INFORMATION = 4
const EVENTLOG_AUDIT_SUCCESS = 8
const EVENTLOG_AUDIT_FAILURE = 16

strMessage = "HomeDirs Batch FIle Copy Started"

set objShell = CreateObject("WScript.Shell")
objShell.LogEvent EVENTLOG_INFORMATION, strMessage


Just change the strMessage to whatever you want and then copy the file to make another one that "ends" the event. Thanks to Pat for the "double greater thans" that append text to a file and to Jake for the sexy VB script.

No comments:

Post a Comment