I have got this code from elsewhere and seems to work when I tested it. But I need it to delete not only all folders and subfolders that have a date modified date older than 1 year but ONLY folders who's parent directory is $ntuninstall*. Can anyone help?
Option Explicit
Const intDaysOld = 365
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder("C:\test")
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
WScript.Echo objSubFolder.DateLastModified
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
WScript.Echo objSubFolder.DateLastModified
objSubFolder.Delete True
End If
Next
Option Explicit
Const intDaysOld = 365
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFolder : Set objFolder = objFSO.GetFolder("C:\test")
Dim objSubFolder
For Each objSubFolder In objFolder.SubFolders
WScript.Echo objSubFolder.DateLastModified
If objSubFolder.DateLastModified < DateValue(Now() - intDaysOld) Then
WScript.Echo objSubFolder.DateLastModified
objSubFolder.Delete True
End If
Next