<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[gOxiA=苏繁=SuFan Blog]]></title> 
<link>https://sufan.maytide.net/index.php</link> 
<description><![CDATA[gOxiA,苏繁,sufan,Microsoft MVP]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[gOxiA=苏繁=SuFan Blog]]></copyright>
<item>
<link>https://sufan.maytide.net/read.php/772.htm</link>
<title><![CDATA[IIS日志删除脚本]]></title> 
<author>gOxiA &lt;sufan_cn@msn.com&gt;</author>
<category><![CDATA[Microsoft IIS]]></category>
<pubDate>Thu, 21 Oct 2004 01:07:57 +0000</pubDate> 
<guid>https://sufan.maytide.net/read.php/772.htm</guid> 
<description>
<![CDATA[ 
	How can I delete all files from my IIS log file directory that are over 90 days old? <br/><br/>这个脚本可以从日志目录中删除90天的记录。<br/><br/><div class="code">Option Explicit<br/>Const GENERAL_FAILURE = 2<br/>Const KillFile=0 ' Set this to 0 to not delete the files, set to 1 to delete the files<br/><br/>Dim ArgObj, Servername, WebSiteID, WebSite, WebSitepath, totalDeleted, MaxAgeOfFileToKeep<br/><br/>Function DeleteOldLogFiles(WebSite, &nbsp;MaxAgeOfFile)<br/>Dim File, ServerObj, FSO, FolderObj, FileObj, LogFileDir, Deleted, Status, FailedToDelete<br/>Deleted = 0<br/>FailedToDelete= 0<br/>on error resume next<br/>' Attempt to get the web site object from the metabase<br/>Err.clear<br/>Set ServerObj = GetObject(WebSite)<br/>If (Err.Number &lt;&gt; 0) Then<br/> &nbsp; WScript.Echo \&quot;Error: \&quot; &amp; Err.Description &amp; \&quot; (\&quot; &amp; Err.Number &amp; \&quot;)\&quot;<br/> &nbsp; Exit Function<br/>end if<br/>LogFileDir = ServerObj.LogFileDirectory<br/>Set ServerObj = Nothing<br/>WScript.Echo \&quot;Log file dir for: \&quot; &amp;WebSite &amp; \&quot; = \&quot; &amp; LogFileDir<br/>WScript.Echo \&quot;Delete files over \&quot;&amp; MaxAgeOfFile &amp; \&quot; days old.\&quot;<br/>WScript.Echo \&quot;\&quot;<br/>Set FSO = CreateObject(\&quot;Scripting.FileSystemObject\&quot;)<br/>set Folderobj = FSO.GetFolder(LogFileDir)<br/>for each File in Folderobj.files<br/> &nbsp;if (Date - File.DateCreated &gt; cint(MaxAgeOfFile)) then<br/> &nbsp; &nbsp; &nbsp; &nbsp; Status = \&quot;Deleting File: \&quot; &amp; File.name &amp; \&quot;, Age=\&quot; &amp; formatNumber(Date-File.DateCreated, 0) &amp; \&quot; days, Status=\&quot; <br/> &nbsp; &nbsp; &nbsp; &nbsp; Err.Clear<br/> &nbsp; &nbsp; &nbsp; &nbsp; if (KillFile = 1) then<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; FSO.DeleteFile(LogFileDir &amp; \&quot;\&quot; &amp; File.Name)<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; If (Err.Number &lt;&gt; 0) Then<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Status = Status &amp; \&quot;Failed : \&quot;&amp; Err.Description &amp; \&quot; (\&quot; &amp; Err.Number &amp; \&quot;)\&quot;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;FailedToDelete = FailedToDelete +1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;else &nbsp; &nbsp; &nbsp; <br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Status = Status &amp; \&quot;Deleted\&quot;<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Deleted = Deleted + 1<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end if<br/> &nbsp; &nbsp; &nbsp; else<br/> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Status = Status &amp; \&quot;Skipped\&quot;<br/> &nbsp; &nbsp; &nbsp; &nbsp;end if<br/> &nbsp; &nbsp; &nbsp; &nbsp;WScript.Echo Status &nbsp;<br/> &nbsp;end if<br/>next<br/>DeleteoldLogfiles = Deleted<br/>WScript.Echo \&quot;\&quot;<br/>if (FailedToDelete &gt; 0) then<br/> &nbsp; WScript.Echo \&quot;There were \&quot; &amp; FailedToDelete &nbsp;&amp; \&quot; files that could not be deleted.\&quot;<br/>end if<br/>WScript.Echo \&quot;There were \&quot; &amp; Deleted &amp; \&quot; files deleted.\&quot;<br/>end function<br/>Sub DisplayHelpMessage()<br/> &nbsp; &nbsp;WScript.Echo<br/> &nbsp; &nbsp;WScript.Echo \&quot;Usage:\&quot;<br/> &nbsp; &nbsp;WScript.Echo \&quot; &nbsp; &nbsp; &nbsp;DeleteOldWebSiteLogfiles.VBS MaxDays WebSiteNumber \&quot;<br/> &nbsp; &nbsp;WScript.Echo<br/> &nbsp; &nbsp;WScript.Echo \&quot;MaxDays = maximum age in days of files to keep.\&quot;<br/> &nbsp; &nbsp;WScript.Echo \&quot;WebSiteNumber is the number of the web site, you have two methods to determine this:\&quot;<br/> &nbsp; &nbsp;WScript.Echo<br/> &nbsp; &nbsp;WScript.Echo \&quot;#1 = Run FINDWEB.VBS\&quot;<br/> &nbsp; &nbsp;WScript.Echo \&quot;#2 = Right click the web site, select properties, on the web site tab\&quot;<br/> &nbsp; &nbsp;WScript.Echo \&quot; &nbsp; &nbsp; under logging click the Properties button, part of the log file\&quot;<br/> &nbsp; &nbsp;WScript.Echo \&quot; &nbsp; &nbsp; name will contain the web site #\&quot;<br/> &nbsp; &nbsp;WScript.Echo<br/> &nbsp; &nbsp;WScript.Echo \&quot; &nbsp; &nbsp; example log filename: W3SVC1\exyymmdd.log &nbsp;- the web site is 1\&quot;<br/> &nbsp; &nbsp;WScript.Echo \&quot; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; W3SVC45\exyymmdd.log - the web site is 45\&quot;<br/> &nbsp; &nbsp;WScript.Echo<br/> &nbsp; &nbsp;WScript.Echo \&quot;Please visit and support : http://www.iisfaq.com\&quot;<br/>end sub<br/>' Get the Arguments object<br/>Set ArgObj = WScript.Arguments<br/>' Test to make sure there is at least one command line arg - the command<br/>If ArgObj.Count &lt; 2 Then<br/> &nbsp; &nbsp; &nbsp; &nbsp;DisplayHelpMessage<br/> &nbsp; &nbsp; &nbsp; &nbsp;WScript.Quit (GENERAL_FAILURE)<br/>End If<br/>Servername = \&quot;LocalHost\&quot;<br/>MaxAgeOfFileToKeep = trim(ArgObj(0))<br/>WebSiteID &nbsp; &nbsp;= trim(ArgObj(1))<br/>WebSite &nbsp; &nbsp; &nbsp; &nbsp;= \&quot;W3SVC/\&quot; &amp; WebSiteID <br/>WebSitepath = \&quot;IIS://\&quot; &amp; Servername &amp;\&quot;/\&quot; &amp; WebSite<br/>TotalDeleted = DeleteOldLogFiles(WebSitePath, &nbsp;MaxAgeOfFileToKeep)</div>
]]>
</description>
</item>
</channel>
</rss>