Option Explicit
Dim FSO, WshShell, Then_Date, WSHShellENV, TempFolder, Recycled
On Error Resume Next
Set FSO = CreateObject("Scripting.FileSystemObject") ' creating a new object to a computer's file system
Set WshShell = WScript.CreateObject("WScript.Shell") ' creates an object in type specified
Set WSHShellENV = WSHShell.Environment("PROCESS")
set TempFolder = FSO.GetFolder(WSHShellENV("TEMP")) ' creates a Folder object to the path you specify
Set Recycled = FSO.GetFolder("C:\test") ' creates a Folder object to the path youspecify and name it
DoDir FSO.GetFolder("C:\deleting") 'set starting directory A MUST
Then_Date = DateAdd("d", -10, Date)
Sub DoDir(Folder)
Dim i, File, SubFolder, fstr, pos, last_mod ' creating variables needed for function
Dim Now_Date, Then_Date ' creates the variable used for today's date
Now_Date = Date ' loads today's date into variable Now_Date
Then_Date = DateAdd("d",-10, Now_Date) ' subtracts ten days from the current date
' WScript.Echo(Then_Date) ' TEST FOR THEN DATE
' WScript.Echo(Now_Date) ' TEST FOR TODAY'S DATE
' WScript.Echo(Folder) ' TEST FOR CORRECT FOLDER
For Each File In Folder.Files ' For each file in folder.files
if ((File.DateLastModified <= Then_Date)) then ' check whether the file IS
' older than keep date
File.delete ' if older than keep date, simply delete it
End if
Next
For Each SubFolder in Folder.SubFolders
DoDir SubFolder
Next
End Sub