临时写了个^_^,调用这个方法就可以了,参数是文件夹路径,和日期'请先引用microsoft script runtimeDim ObjFS As New Scripting.FileSystemObject Private Function DeleteFile(ByVal SorcePath As String, ByVal dFileDate As String) On Error Resume Next Screen.MousePointer = 11 Dim Folder1 As Folder Dim File1 As File
Set Folder1 = ObjFS.GetFolder(SorcePath) For Each File1 In Folder1.Files If CDate(Format(dFileDate, "yyyy/mm/dd hh:mm:ss")) > CDate(File1.DateCreated) Then ObjFS.DeleteFile SorcePath & "\" & File1.Name, True End If
http://www.vbaspnew.com/ziyuan/y/wj/f007.ZIP遍历目录,用上面的函数获取文件日期,进行比对就可以实现你的要求了
Private Function DeleteFile(ByVal SorcePath As String, ByVal dFileDate As String)
On Error Resume Next
Screen.MousePointer = 11
Dim Folder1 As Folder
Dim File1 As File
Set Folder1 = ObjFS.GetFolder(SorcePath)
For Each File1 In Folder1.Files If CDate(Format(dFileDate, "yyyy/mm/dd hh:mm:ss")) > CDate(File1.DateCreated) Then
ObjFS.DeleteFile SorcePath & "\" & File1.Name, True
End If
Next
Screen.MousePointer = 0
End Function