' ********************************************************************* ' ' Name : BackupAndClearLogFile.vbs ' Author : 3Ds (UK) Limited ' Description : Example VBScript to backup, then clear a text-based ' log file. ' ' Arguments : None. ' ' WIZARD:PARAMS=This script requires no parameters ' WIZARD:PARAMEXAMPLE= ' ' Returns : 0 - Success ' 1 - An error occurred and the information could not be ' logged. ' ' WIZARD:RESULTS=Return code ...||0 = OK|1 = An error prevented the script from completing successfully.||If an error occurs, a message will be output giving details of the fault encountered. ' ' Notes : Requires Windows Scripting Host (for VBScript). ' ' Change the "TODOs" for your own requirements. ' ' ********************************************************************* ' Enable in-line error handling On Error Resume Next ' ------ Local declarations ------ Dim objFSO ' File System Object Dim strFileName ' The file to backup/clear down ' ------ Main Logic ------ ' TODO: Set the filename strFileName = "C:\Data\Logs\Sentry-go.txt" ' Create the FSO Set objFSO = CreateObject("Scripting.FileSystemObject") If Err.Number <> 0 Then ' Error WScript.Echo "Unable to create the file system object. " & Err.Description WScript.Quit(1) End If ' Ensure the backup doesn't already exist - it may not so ignore any error objFSO.DeleteFile strFileName & ".bak" Err.Clear ' Move the file objFSO.MoveFile strFileName, strFileName & ".bak" If Err.Number <> 0 Then ' Error WScript.Echo "Unable to move the file " & strFileName & " to " & strFileName & ".bak. " & Err.Description Set objFSO = Nothing WScript.Quit(1) End If ' ------ Cleanup ------ Set objFSO = Nothing WScript.Quit(0) ' ------ End of Script ------