I need to delete files from the C:\Company\Temp directory that are older than 120 days. I have to perform this on about 125 PCs. The VBScript keeps bombing on line 27, character 1, where my objFile is setup. When I remove this line it tells me I need to use objFile. I'm missing something and need a little help.
dtmDate = Date - 120
strDay = Day(dtmDate)
If Len(strDay) < 2 Then
strDay = "0" & strDay
End If
strMonth = Month(dtmDate)
If Len(strMonth) < 2 Then
strMonth = "0" & strMonth
End If
strYear = Year(dtmDate)
strTargetDate = strYear & strMonth & strDay
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\Company\Temp'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in FileList
strDate = Left(objFile.CreationDate, 8)
If strDate < strTargetDate Then
objFile.Delete
End If
Next