Script to delete old log files on Windows Server 2003

130 pts.
Tags:
Batch files
Scripting
Windows scripting
Windows Server 2003
Hi all, looking for a script or batch file that I can call from schedule tasks that will delete some older Symantec log files that keep filling up my C: drive. Any suggestion or pointers would be appreciated. Thanks in advance! Paul

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hello, I think that this will solve your problem, just save the following code as whateveryoulike.vbs and schedule it (remember: the user that runs the scheduled job must have access to the “WhatchFolder“).

<pre>
Const WhatchFolder = "C:\TheFolder"
Const MaxDays = 30
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(WhatchFolder)
Set colFiles = objFolder.Files
For Each objFile in colFiles
If DateDiff("d",objFile.DateCreated,now) >= MaxDays Then
objFSO.DeleteFile(objFile.Path)
End If
Next
</pre>

I hope this helps.

Sorry a bit late to this post but, I have some VBScript code that I use to delete and/or archive files on a number of machines… I would suggest looking at my code and using as-is or incorporating the useful code into your script.

The code is here.
Additional details about its capabilities are on this page as well.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Jerry Lees
    You can do this with the file system object in vbscript, relatively easily. What is the format of the names of the files you wish to delete? Is the date encoded intt the file?
    5,335 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following