View Single Post
  #9 (permalink)  
Old 05-12-2009, 12:30 PM
RadHaz75's Avatar
RadHaz75 RadHaz75 is offline
BES Expert
 
Join Date: May 2009
Location: Philadelphia, PA
Posts: 98
Default

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
__________________
Two months ago, I saw a provocative movie on cable TV. It was called The Net, with that girl from the bus.

Last edited by RadHaz75; 05-12-2009 at 12:34 PM.
Reply With Quote