本文共 913 字,大约阅读时间需要 3 分钟。
Dim fso,s,DeleteCount Set fso = CreateObject("Scripting.FileSystemObject") DeleteCount = DeleteCount + Xdelete(fso, "E:\baktest") MsgBox "删除了" & DeleteCount & "个文件!" Function Xdelete(fso, source) Dim f0,f,DeleteCount,s,f2 Set s = fso.GetFolder(source) 'f0=s.datelastmodified '获取当前文件夹的最新更新时间 datelastmodified DateCreated f0="2000-01-01 00:00:00" For Each f2 In s.Files 'msgbox "begin " If datediff("s",f0,f2.datelastmodified)>0 and right(f2.name,4) = ".bak" Then 'msgbox f2.name & f2.datelastmodified &f0 f0=f2.datelastmodified 'datelastmodified DateCreated End if Next 'Msgbox f0 DeleteCount = 0 For Each f In s.Files If datediff("s",f.datelastmodified ,f0)>0 Then ' datelastmodified DateCreated f.Delete False '删除文件 ' msgbox f.name & f.datelastmodified &f0 DeleteCount = DeleteCount + 1 End if Next For Each f In s.SubFolders DeleteCount = DeleteCount + Xdelete(fso, f.Path) Next Xdelete=DeleteCount End Function转载地址:http://xafmi.baihongyu.com/