copy from http://www.cnblogs.com/MasterMonkInTemple/p/7655734.html
dim folder, file, mFSO, subfolder
Set mFSO = CreateObject(
"Scripting.FileSystemObject"
)
set folder=mFSO.GetFolder(
"C:UsersmsautotestuserAppDataLocalTemp"
)
'Delete files
dim df
For Each file In folder.files
'df=DateDiff("h",file.DateCreated,Now) '
Create Date
df=DateDiff(
"h"
,file.DateLastModified,Now) 'Modify Date
If (df>
2
) Then '
2
hours ago
'MsgBox folder.path & "" & file.Name & vbTab & file.DateCreated
'MsgBox folder.path & "" & file.Name & vbTab & file.DateLastModified
On Error Resume Next
file.Delete()
End If
Next
'Delete folders
set subfolder = Folder.subFolders
For Each file In subfolder
'df=DateDiff("h",file.DateCreated,Now) '
Create Date
df=DateDiff(
"h"
,file.DateLastModified,Now) 'Modify Date
If (df>
2
) Then '
2
hours ago
On Error Resume Next
mFSO.deleteFolder(folder.path & "" & file.Name)
end
if
next