strRoot = "c:\temp"
strMask = "*.*"
blnSubFolders = False
intHours = 2
strCommand = "cmd /c @echo off & dir " & Chr(34) & _
strRoot & "\" & strMask & Chr(34) & " /a:-d /b"
If blnSubFolders Then
strCommand = strCommand & " /s"
End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = CreateObject("WScript.Shell")
Set objWshScriptExec = objShell.Exec(strCommand)
Set objStdOut = objWshScriptExec.StdOut
Do Until objStdOut.AtEndOfStream
strFile = objStdOut.ReadLine
If Not blnSubFolders Then
strFile = strRoot & "\" & strFile
End If
Set objFile = objFSO.GetFile(strFile)
If DateDiff("h", objFile.DateLastModified, Now) > intHours Then
WScript.Echo "Delete " & strFile
'objFile.Delete True
End If
Loop
|