I have a vbscript that I want to run to delete all files and folders that are older than 24 hours, and it should NOT delete a directory if it has files or folders in it that is younger than 24 hours. But when I try to run my script i get an error saying
Error: Ojbect doesn't support this property or method
Which means there is something wrong with this line in the script
"If Flag = "yes" then objSubFolder.Delete(True)"
But I don't know what's wrong with it.
I appreciate all the help i can get.
This is my current script:
Const strPath = "D:\shared\temp"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call Search (strPath)
Dim objFolder, objSubFolder, objFile
Set objFolder = objFSO.GetFolder(str)
For Each objFile In objFolder.Files
If objFile.DateCreated < (Now() - 1) Then
For Each objSubFolder In objFolder.Subfolders
Flag = ""
If objSubFolder.DateCreated < (Now() - 1) Then
For Each Thing in objSubFolder
If thing.DateCreated > Now() - 1 then Flag="yes"
If Flag = "yes" then objSubFolder.Delete(True)