I need a VBS script that can monitor old folders and delete their contents when they are out of date. Please tell me how I can do this.
Â
VBS to monitoring folder older then easily work
Hi Jessica Allen,
Â
Please find the below code to delete files older than a specific date.
Â
Â
Dim fileObject, folder, file, files
Â
strDir = "Give Full path of Destination folder"
strDays = "Give number of days"
Â
Set fileObject = CreateObject("Scripting.FileSystemObject")
Set folder = fileObject.GetFolder(strDir)
Set files = folder.Files
Â
For Each file in files
   If DateDiff("d", file.DateCreated, Date) > strDays Then
      fileObject.DeleteFile(file)
   End If
Next
WScript.Quit
Â
Give the path name of the folder and the number of days for which you want to delete the file.
Â
Hope it helps