Solved

Script to clear log files which are 15 days old.

Posted on 2011-09-04
4
274 Views
Last Modified: 2012-06-27
Hi,
Looking for script which will clear up log files which are older than 15/20 days on C drive with below path
c$\WINNT\system32\LogFiles
THis is to ensure that we do not run out of disk space on that drive.
Let me know if anyone has used such script.
Thanks.
0
Comment
Question by:ex_ad
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 1

Expert Comment

by:danmb
ID: 36480602
Well I found a script "VBScript to Delete Old Files" by Sidd at http://www.symantec.com/connect/downloads/vbscript-delete-old-files, and made some changes to it.

For safety's sake, because I don't want to be responsible for deleting files on your computer, please review the 3 lines that are commented with "Specify:" and make sure they have the
- correct directory path,
- correct age of files to delete, and
- correct file extension of the files to delete (no dot, just the extension).

Once you've done that, you must also manually uncomment the line that actually does the deletion.

'                   oFile.Delete(True)


' Based on "VBScript to Delete Old Files" by Sidd
' http://www.symantec.com/connect/downloads/vbscript-delete-old-files
' with some changes to the file extension code
'
' For safety sake, please review the 
' - Directory Path, 
' - Age of Files, and
' - Extension of Files to Delete 
' lines, and modify as necessary.
'
' You must also UNCOMMENT  
' oFile.Delete(True) 
' to actually do the deletion.
'

Option Explicit 
On Error Resume Next 
Dim oFSO, oFolder, sDirectoryPath 
Dim oFileCollection, oFile, sDir 
Dim iDaysOld, sExt


' *************************************************


' Specify Directory Path From Where You want to clear the old files 

sDirectoryPath = "c:\WINNT\system32\LogFiles" 

' Specify Age of Files to Delete, in Days

iDaysOld = 20

' Specify extension of files to delete (no ".", just the extension)

sExt = "log"


' *************************************************


sExt = LCase(sExt)

Set oFSO = CreateObject("Scripting.FileSystemObject") 
Set oFolder = oFSO.GetFolder(sDirectoryPath) 
Set oFileCollection = oFolder.Files 

For each oFile in oFileCollection
	If LCase(oFSO.GetExtensionName(oFile)) = sExt Then
 		If oFile.DateLastModified < (Date() - iDaysOld) Then 

' ********************************** 

' *** (optional) Comment the following line
			msgbox (oFile & " would be deleted, " & oFile.DateLastModified)

' *** and Uncomment the following line, which actually does the deletion.
'	 		oFile.Delete(True) 

' **********************************

 		End If 
 	End If   
Next 

Set oFSO = Nothing 
Set oFolder = Nothing 
Set oFileCollection = Nothing 
Set oFile = Nothing

Open in new window

0
 
LVL 54

Accepted Solution

by:
Bill Prew earned 500 total points
ID: 36481682
You could just grab a copy of this great utility, it excels at exactly this, for free.

http://www.horstmuc.de/win/delage.htm

http://www.horstmuc.de/wbat32.htm

~bp
0
 
LVL 7

Expert Comment

by:BobintheNoc
ID: 36482039
Since the folder structure suggests an originally WINNT 4 system, i'm guessing this ain't on a 2008 server?

Within Win7 and Win2008, there's a new piece on the command line, FORFILES, and it's used for stuff EXACTLY like you're wanting, all within CMD's internals.

Otherwise, should be lots to find on a download site for shareware.
0
 

Author Closing Comment

by:ex_ad
ID: 36813836
thx
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Utilizing an array to gracefully append to a list of EmailAddresses
This script can help you clean up your user profile database by comparing profiles to Active Directory users in a particular OU, and removing the profiles that don't match.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question