'------------------------------------------------------------------------------------------------
'
' Usage: delete files on the ftp folder that are over two days
'
' 2002/5/16 Darmen Created
'
'------------------------------------------------------------------------------------------------
' Force explicit declaration of all variables.
Option Explicit
On Error Resume Next
Dim CurrentDate, FileCreatedDate, FolderCreatedDate
Dim fs
Set fs = CreateObject("Scripting.FileSystemObject")
'get current time
CurrentDate = Now
'get the count of log files in ftp root folder
Dim LogFile, nCount, TempFolder, TempFileColl
Set TempFolder = fs.GetFolder(strLogFolderPath)
Set TempFileColl = TempFolder.Files
nCount = TempFileColl.Count
Sub DeleteOutDateFolder( folder, IsRootFolder )
Dim fileColl, folderColl, file, subfolder
Set fileColl = folder.Files
'delete out date files in this folder
For Each file in fileColl
DeleteOutDateFile(file)
Next
Set folderColl = folder.SubFolders
'delete out date sub folders in this folder
For Each subfolder in folderColl
DeleteOutDateFolder subfolder, False
Next
Set fileColl = folder.Files
Set folderColl = folder.SubFolders
'judge if this folder is empty or not
If fileColl.Count <> 0 Then
Exit Sub
Else
If folderColl.Count <> 0 Then
Exit Sub
End If
End If
FolderCreatedDate = folder.DateCreated
'judge if this folder was created two days ago or not
If IsRootFolder = True Then
Exit Sub
End If
If CurrentDate - FolderCreatedDate >= 2 Then
LogFile.WriteLine Now & " delete folder: " & folder.Path
folder.Delete
End If
End Sub
Sub DeleteOutDateFile( file )
FileCreatedDate = file.DateCreated
'if this file was created two days ago,delete it!
If CurrentDate - FileCreatedDate >= 2 Then
LogFile.WriteLine Now & " delete file: " & file.Path
file.Delete
End If
End Sub