SoFunction
Updated on 2025-04-09

Recommended code to clean iis logs with multiple scripts


Sometimes when I get other people's code, I have to write a bunch of things to test. Now if you ask me to test this, you won't test it directly on the server. So, below, I will post my test script by Liu Yongfa, which mainly generates a test folder on D disk and some IIS test log files.

IIS log cleanup IIS log generation system():

'IIS log cleanup IIS log generation system()
'Create a folder
Function CreateFolder(Folder)   
    On Error Resume Next  
    Set FSO = CreateObject("")   
    (Folder)   
    If Err>0 Then  
          
        CreateFolder = False  
    Else  
        CreateFolder = True  
    End If  
End Function  
'Create a file
Function CreateFile(FileName, Content)   
    On Error Resume Next  
    Set FSO = CreateObject("")   
    Set fd = (FileName, True)   
     Content   
    If Err>0 Then  
          
        CreateFile = False  
    Else  
        CreateFile = True  
    End If  
End Function  

  
CreateFolder "D:\IISLogTest"  
CreateFolder "D:\IISLogTest\IISLogs001"  
CreateFolder "D:\IISLogTest\IISLogs002"  
CreateFolder "D:\IISLogTest\IISLogs003"  
for i=1 to 30   
    d=date-i   
    filename="ex" & right(year(d),2) & right("0" & month(d),2) & right("0" & day(d),2) & ".log"  
    CreateFile "D:\IISLogTest\" & filename,Content   
    CreateFile "D:\IISLogTest\IISLogs001\" & filename,Content   
    CreateFile "D:\IISLogTest\IISLogs002\" & filename,Content   
    CreateFile "D:\IISLogTest\IISLogs003\" & filename,Content   
next  

'IIS log cleanup IIS log generation system()
Copy the codeThe code is as follows:

'Create a folder
Function CreateFolder(Folder) 
    On Error Resume Next 
    Set FSO = CreateObject("") 
    (Folder) 
    If Err>0 Then 
         
        CreateFolder = False 
    Else 
        CreateFolder = True 
    End If 
End Function 
'Create a file
Function CreateFile(FileName, Content) 
    On Error Resume Next 
    Set FSO = CreateObject("") 
    Set fd = (FileName, True) 
     Content 
    If Err>0 Then 
         
        CreateFile = False 
    Else 
        CreateFile = True 
    End If 
End Function 


CreateFolder "D:\IISLogTest" 
CreateFolder "D:\IISLogTest\IISLogs001" 
CreateFolder "D:\IISLogTest\IISLogs002" 
CreateFolder "D:\IISLogTest\IISLogs003" 
for i=1 to 30 
    d=date-i 
    filename="ex" & right(year(d),2) & right("0" & month(d),2) & right("0" & day(d),2) & ".log" 
    CreateFile "D:\IISLogTest\" & filename,Content 
    CreateFile "D:\IISLogTest\IISLogs001\" & filename,Content 
    CreateFile "D:\IISLogTest\IISLogs002\" & filename,Content 
    CreateFile "D:\IISLogTest\IISLogs003\" & filename,Content 
next 

Postscript: This method can not only be used in IIS log processing, but also in Serv-U log processing. The prerequisite is that the format of the Serv-U log file must also be set to a format like IIS logs.