Hello all, I have a script that looks for any file with a certain extention and deletes it. The problem I have is it will not look in the subfolders of the folder I have specified. I understand this is a difficult request so I am asking for help. I have pasted what I have so far below. Any assistance would help a ton.
Thx
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='D:\'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
If objFile.Extension = "pfc" Then
'strCopy = "D:\Operation Logs\" & objFile.FileName _
'& "." & objFile.Extension
'objFile.Copy(strCopy)
objFile.Delete
End If
Next
Thx
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='D:\'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
If objFile.Extension = "pfc" Then
'strCopy = "D:\Operation Logs\" & objFile.FileName _
'& "." & objFile.Extension
'objFile.Copy(strCopy)
objFile.Delete
End If
Next