程序代码:
Dim datetmp As String
Dim fso As Object
Dim f1 As Object, f2 As Object, f3 As Object, f4 As Object, f5 As Object
Set fso = CreateObject("scripting.filesystemobject")
Set f1 = fso.getfolder(Text1.Text)
Set f2 = f1.Files
Set f3 = f1.subfolders
For Each f4 In f2
datetmp = fso.getfile(f4.Path).datecreated
If DateDiff("d", datetmp, Now) > Combo1.Text Then
fso.getfile(f4.Path).Delete
End If
Next
For Each f5 In f3
If fso.getfolder(f5.Path).Size = 0 Then
fso.getfolder(f5.Path).Delete
End If
Next
谢谢风老师,这个我已纠正过来,可以删除过期文件。
Dim fso As Object, fpath As String
Dim myfolder As Object
fpath = "E:\初中同学"
Set fso = CreateObject("scripting.filesystemobject")
Set myfolder = fso.getfolder(fpath)
For Each Item In myfolder.Files
If UCase(Right(Item, 3)) = "TXT" Then Print Item
Next
Set fso = Nothing
在这个基础上进行文件日期判断,取的是item.datecreated吗?