以下代码未经测试,你试试看:
Public Function DelFiles(FldPath As String, Mydate As Date, str As String)
'引用:Microsoft Scripting Runtime
'功能:删除备份文件
'参数:FldPath--文件夹地址; Mydate--删除文件的创建日期范围; str--备份文件的扩展名
'示例:DelFiles CurrentProject.Path & "\备份文件夹",2010/8/1,"BAK"
Dim FSO As New FileSystemObject
Dim Fld As Folder
Dim Fil As File
If FSO.FolderExists(FldPath) = True Then
Set Fld = FSO.GetFolder(FldPath)
For Each Fil In Fld.Files
If Right(Fil.Name, InStrRev(Fil.Name, ".") + 1) = str Then
If Fil.DateCreated <= Mydate Then
FSO.DeleteFile Fil.Path
End If
End If
Next Fil
End If
Set Fil = Nothing
Set Fld = Nothing
Set FSO = Nothing
End Function