Hi,
What is the file type for this script, is it .vbs?
I changed BES logs directory and I changed it to 15 days, but when I run it, nothing happens.
Thanks in advance.
Quote:
Originally Posted by RadHaz75
fixed a few bugs in your script. it now writes what files it deletes the log and records the date when it finishes.
also if you have the "debug log max daily file age" set, then your folders will have been modified more recently (mine was set to 7 days) and thus not all folders you might expect would be deleted. i changed the one param to folderObject.DateCreated and it then only leaves exactly 7 days (or whatever u specify). it won't delete the webserver logs as they're in use. make sure you move your installer files if you need them as they will be deleted.
'THIS SCRIPT Checks for folders older than 7 days in the path D:\BESLog\BlackBerry Enterprise Server\Logs.
'If folders are older than 7 days they are deleted.
'A logfile is written to the D:\BESLog\BlackBerry Enterprise Server\Logs path on completion.
'This logfile is overwritten at each run.
On Error Resume Next
'Define the constants
'Number of days to retain the folder
CONST ADJUSTDATE = -7
'Enter your folder path to the BlackBerry logs below
CONST FOLDERPATH = "D:\BESLog\BlackBerry Enterprise Server\Logs"
CONST FILENAME = "DeleteLogsScript.log"
'Get the File System Objects
Set fso = CreateObject("Scripting.FileSystemObject")
Set folder = fso.GetFolder(FOLDERPATH)
Set subFolders = folder.SubFolders
'Set the log file
sLogFilePath = FOLDERPATH & "\" & FILENAME
set logfile = fso.CreateTextFile(sLogFilePath, True)
'Write the log file
logfile.WriteLine("BES Delete Logs started on " & Now )
logfile.WriteLine("The following folders were deleted")
'Set the date to delete folders older than
dateold = DateAdd("d", ADJUSTDATE, Date)
'Process all the folders
For Each folderObject in SubFolders
ErrorValue = 0 'ensure the error value is reset for each folder
datemod = DateValue(folderObject.DateLastModified)
'Delete folders that are old
IF datemod < dateold Then
folname = folderObject.path
fso.DeleteFolder folderObject, true 'this line deletes the folders
ErrorValue = Err.Number
If ErrorValue = 76 Then
'The folder was deleted ok
logfile.WriteLine (folname & " successfully deleted.") 'record folders that were successfully deleted
Else
If ErrorValue = 70 Then
'Error value 70 denotes the folder could not be deleted for access reasons. Most likely the folder (or a file within it) is in use.
logfile.WriteLine (folderObject.path & " could not be deleted. This folder, or a file within it, may be in use.")
Else
logfile.WriteLine (folderObject.path & " could not be deleted. Unknown error")
End If
End If
End IF
Next
'Write the log file
logfile.WriteLine("BES Delete Logs Completed on " & NOW)
logfile.Close
'Clear the variables
Set subFolders = Nothing
Set folder = Nothing
Set fso = Nothing
Set logfile = Nothing
Set folname = Nothing
|