Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to delete folder and contents based on modified date

Status
Not open for further replies.

tyant

Programmer
Jun 1, 2001
68
AU
I'm not a programmer .... Technical User. I found the below script to delete files after 30 days. I hope the script will delete a folder and all its contents based on modified date

NumberOfDaysOld = 30
strPath = "C:\Test"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPath)
Set colSubfolders = objFolder.Subfolders
Set colFiles = objFolder.Files

For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next

For Each objSubfolder in colSubfolders
Set colFiles = objSubfolder.Files
For Each objFile in colFiles
If objFile.DateLastModified < (Date() - NumberOfDaysOld) Then
objFile.Delete
End If
Next

Next
 
Believe this is in wrong forum. It's VBScript I am looking for

Thanks

Tyant
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top