asked on
Dim iDaysOld
Dim objFSO
Dim objShell
Dim strEnv
Dim sDirectoryPath
Dim objFolder
Dim objFileCollection
Dim objFile
iDaysOld = 30
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
strEnv = objShell.ExpandEnvironmentStrings("%temp%")
sDirectoryPath = strEnv
Set objFolder = objFSO.GetFolder(sDirectoryPath)
Set objFileCollection = objFolder.Files
For Each objFile in objFileCollection
If objFile.DateLastModified < (Date() - iDaysOld) Then
objFile.Delete(True)
End If
Next
Set objFSO = Nothing
Set objFolder = Nothing
Set objFileCollection = Nothing
Set objFile = Nothing