VBS to monitoring folder older then easily work

Asked By 30 points N/A Posted on -
qa-featured

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.

 

SHARE
Answered By 0 points N/A #174878

VBS to monitoring folder older then easily work

qa-featured
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

Related Questions