Solved

Script to clear log files which are 15 days old.

Posted on 2011-09-04
4
270 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
4 Comments
 
LVL 1

Expert Comment

by:danmb
Comment Utility
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 51

Accepted Solution

by:
Bill Prew earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
thx
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Are you one of those front-line IT Service Desk staff fielding calls, replying to emails, all-the-while working to resolve end-user technological nightmares? I am! That's why I have put together this brief overview of tools and techniques I use in o…
Microsoft Windows Server Update Service (WSUS) is free for everyone, but it lacks of some desirable features like send an e-mail to the administrator with the status of all computers on the WSUS server. This article is based on my PowerShell script …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now