用于删除> 30天之前的文件夹和文件的脚本

时间:2011-03-15 16:25:47

标签: vbscript filesystems

我有一些VBS脚本,我一直在2个不同的目录中使用。在1个目录中,它会删除超过30天的文件夹,另一个目录会删除超过30天的文件。我让他们设置为运行计划任务,但是他们运行一次或两次然后停止工作。 我正在寻找有关他们停止工作的原因或新脚本的任何见解。 以下是我目前使用的两个脚本。 非常感谢您的任何见解!我很感激!!!

'******************* Start of Code *************************

Option Explicit 
On Error Resume Next 
Dim oFSO, oFolder, sDirectoryPath  
Dim oFileCollection, oFile, sDir  
Dim iDaysOld 

' Specify Directory Path From Where You want to clear the old files 

sDirectoryPath = "C:\WINDOWS\system32\LogFiles\W3SVC823230" 

' Specify Number of Days Old File to Delete

iDaysOld = 15

Set oFSO = CreateObject("Scripting.FileSystemObject") 
Set oFolder = oFSO.GetFolder(sDirectoryPath) 
Set oFileCollection = oFolder.Files 

For each oFile in oFileCollection

'This section will filter the text file as i have used for for test 
'Specify the Extension of file that you want to delete 
'and the number with Number of character in the file extension  

    If LCase(Right(Cstr(oFile.Name), 3)) = "log" Then

        If oFile.DateLastModified < (Date() - iDaysOld) Then 
        oFile.Delete(True) 
        End If 

    End If     
Next 

Set oFSO = Nothing 
Set oFolder = Nothing 
Set oFileCollection = Nothing 
Set oFile = Nothing 

'************************ End of Code ********************

0 个答案:

没有答案
相关问题