I am new to VB Script, please help me with the below code.
I have a requirement where i need to delete all files in a folder older than x days and file name starting with xxxyyyzzz.log.
I have below code, but it is throwing
error as error in line 16
Const strPath = "C:\Users\xyz\Downloads"
Dim objFSO
Set objFSO = CreateObject("Scripting.FileSystemObject")
Call Search (strPath)
WScript.Echo"Done."
Sub Search(str)
Dim objFolder, objSubFolder, objFile
Set objFolder = objFSO.GetFolder(str)
For Each objFile In objFolder.Files
If Not ((objFile.filename = xxx*.log) And (objFile.DateCreated < (Now() - x)) Then
objFile.Delete(True)
End If
Next
For Each objSubFolder In objFolder.SubFolders
Search(objSubFolder.Path)
If (objSubFolder.Files.Count = 0) Then
objSubFolder.Delete(True)
End If
Next
End Sub