VBS to monitoring folder older then easily work

Asked By 30 points N/A Posted on -

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.


Answered By 0 points N/A #174878

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
      End If
Give the path name of the folder and the number of days for which you want to delete the file.
Hope it helps

Login/Register to Answer

Related Questions