Tim

Footprints in the snow of a warped mind

Automatically delete old IIS log files

Where to find me

Flickr Icon  Twitter Icon  Linked In Icon  FaceBook Icon  Windows Live Alerts Butterfly  RSS 2.0 

Tag Cloud

AJAX (4) ASP (6) ASP.Net (50) Error Reporting (4) Web Service (1) WSDL (1) Atlas (2) Business (76) Business Start-up Advice (25) Client (14) Expanding Your Business (17) C# (16) Canoeing (4) Canoe Racing (5) Cheshire Ring Race (5) Racing (2) Training (4) CIMA (1) Cisco (1) 7970G (1) CSS (3) dasBlog (4) DDD (1) Design (9) Icons (1) Development (12) General (39) Christmas (6) Fun and Games (11) Internet (22) Random (46) RX-8 (8) Home Cinema (2) Hosting (2) IIS (10) iPhone (1) JavaScript (4) jQuery (1) Marketing (5) Email (1) Multipack (1) Networking (2) Nintendo (1) OS Commerce (1) Photography (1) PHP (1) PowerShell (2) Press Release (1) Productivity (2) Security (2) SEO (5) Server Maintenance (4) Server Management (9) Social Media (1) Social Networking (2) Experiment (1) Software (9) Office (5) Visual Studio (12) Windows (4) Vista (1) SQL (1) SQL Server (13) Stored Procedure (1) Testing (1) The Site Doctor (104) Turnover Challenge (1) Twitter (2) Umbraco (17) 2009 (1) Web Development (54) WebDD (33) Wii (1)

Blog Archive

Search

<February 2007>
SunMonTueWedThuFriSat
28293031123
45678910
11121314151617
18192021222324
25262728123
45678910

Recent Comments

Blog Archive

Various Links

Blogs I Read

[Feed] Google Blog
Official Google Webmaster Central Blog
[Feed] Matt Cutts
Gadgets, Google, and SEO
[Feed] Ol' Deano's Blog
My mate Dean's blog on my space, equally as random as mine but not off on as much of a tangent!
[Feed] Sam's Blog
Sam is one of my younger brothers studying Product Design and Manufacture at Loughborough, this is his blog :) Enjoy!

Recent Tracks

last.fm - The Social Music Revolution

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

newtelligence dasBlog 2.2.8279.16125

Send mail to the author(s) Email Me (Tim Gaunt)

© 2010 Tim Gaunt.

Sign In

    # Saturday, February 10, 2007

    Automatically delete old IIS log files

    Saturday, February 10, 2007 4:23:10 PM (GMT Standard Time, UTC+00:00)

    This is a really useful little VBS script that I’ve been meaning to post for a while now (along with a couple of other little applications I’ve written for log file analysis). I don’t think I wrote this script but at the same time can’t recall where it came from.

    It basically traverses the FSO finding files with the designated extension and assuming the match the standard IIS date format, checks whether they’re older than x days, if they are deletes them. Running it is simple, place somewhere obvious on the server and just double click it. Alternatively if you want to read the output, run it from CMD. For safety’s sake, the first time you run it I would leave it just printing out the files that will be deleted.

    Personally I don’t schedule this script as although automation is great, I’ll probably have it delete the logs before I’ve had a chance to download them so what I tend to do is download the logs and then after that (or the next time I’m on RDC) I run it, I find that way I ensure I get all the log files i.e. if I go on holiday.

    I’ve got two other applications that I’ll post shortly, one outputs the location of the log files for each domain name within IIS and the other combines the log files into one for analysis –it also takes the exported file/folder locations and names the combined log files with the domain’s name –saves a ton of time!

    Download the VBS script as a ZIP file

    Option Explicit

    Dim intDaysOld, strObjTopFolderPath, strLogFIleSuffix, ObjFS, ObjTopFolder 
    Dim ObjDomainFolder, ObjW3SvcFolder, ObjSubFolder, ObjLogFile, ObjFile

    intDaysOld        = 5        'Number of days to retain on the server
    strObjTopFolderPath    = ""        'The location of your log files
    strLogFIleSuffix    = ".log"    'The suffix of your log files

    Set ObjFS = CreateObject("Scripting.FileSystemObject")
    Set ObjTopFolder = ObjFS.GetFolder(strObjTopFolderPath)

    For Each ObjDomainFolder in ObjTopFolder.SubFolders
    WScript.Echo("Folder: " & ObjDomainFolder.name)
        For Each ObjW3SvcFolder in ObjDomainFolder.SubFolders
            WScript.Echo("  Folder: " & ObjW3SvcFolder.name)
            Set ObjSubFolder = ObjFS.GetFolder(ObjW3SvcFolder)
                For each ObjLogFile in ObjSubFolder.files
                    Set ObjFile = ObjFS.GetFile(ObjLogFile)
                    If datediff("d",ObjFile.DateLastModified,Date()) > intDaysOld and lcase(right(ObjLogFile,4))=strLogFIleSuffix then
                        '*****************************************************
                        'DON'T UNCOMMENT THIS UNTIL YOU KNOW IT WORKS PROPERLY!!!
                        WScript.Echo("    Will delete " & ObjSubFolder.name & "\" & ObjFile.name)
                        'WScript.Echo("    Deleted " & ObjSubFolder.name & "\" & ObjFile.name)
                        'ObjFile.Delete
                        '*****************************************************
                    End If
                    Set ObjFile = nothing
                Next
            Set ObjSubFolder = nothing
        Next
    Next

    Set ObjTopFolder = nothing
    Set ObjFS = nothing
    Automatically delete old IIS log files
    Useful Links:  #  digg it!  del.icio.us  Technorati  email it!  Post CommentsComments [10]  Trackback LinkTrackback
    CategoriesTags: IIS | Windows