?
Solved

VB Script to clear out log files

Posted on 2007-10-18
7
Medium Priority
?
759 Views
Last Modified: 2012-08-13
I need a script that will automatically clear out  log files older then a week and runs daily.   I'm a complete novice when it comes to VBScript so any and all help setting this up would be appreciated.  
0
Comment
Question by:bpp2444
  • 3
  • 3
7 Comments
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20106835
Are you referrring to the log files in the eventviewer or the log files stored in any of the folders.
0
 

Author Comment

by:bpp2444
ID: 20107335
Both would actually be helpful ;)
0
 
LVL 12

Accepted Solution

by:
chandru_sol earned 1000 total points
ID: 20107354
Try this to delete the log files in a specific folder. Change the location to suit your needs...

Dim oFSO
Dim oFolder
Dim oFile
Dim iDaysOld


'Customize values here to fit your needs
      iDaysOld=7
      Set oFSO=CreateObject("Scripting.FileSystemObject")
      set oFolder=oFSO.GetFolder("C:\Scripts\logss")
      

'Walk through each file in this folder collection.
'If it is older than 7 days, then delete it.

For each oFile in oFolder.Files
If oFile.DateLastModified < (Date() - iDaysOld) Then                               
oFSO.DeleteFile oFolder.Path & "\" & oFile.Name
End If
Next

'Clean up
      Set oFSO = Nothing
      Set oFolder = Nothing
      Set oFileCollection = Nothing
      Set oFile = Nothing

This will delete all the files in the folder C:\Scripts\logss. If you want we can change this to delete specific file extensions
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:bpp2444
ID: 20107379
Alright I have to add to this cause like I said I'm really new to this, in turn I will bump the points up to 500 ;)))  What is my best option to set this up to run daily at a specific time???  Do I just put this in a specific folder and set a basic dos script to run everyday?  Thank you for your help chandru sol.  
0
 
LVL 12

Expert Comment

by:chandru_sol
ID: 20107404
Hi,

I would suggest just run a scheduled task daily and you can select the file. Before that you save the above script as delold.vbs and select the same file in the scheduled task to run everyday.

0
 

Author Comment

by:bpp2444
ID: 20107438
Thats what I was thinking just wanted to be sure, good deal ;)))  I will try this out.  
0
 
LVL 65

Expert Comment

by:RobSampson
ID: 20113239
Hi guys, just thought I'd put in my 2 cents....Event Logs from the Event Viewer cannot be partially cleared.  It is all or nothing......but they *can* be backed up and stored for import again later.

Regards,

Rob.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Loops Section Overview
Suggested Courses
Course of the Month14 days, 19 hours left to enroll

839 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