I need a script to search a folder and subfolders for certain file extensions then move the folder and all it contents to another folder.I have a script that will find a certain extension and move it but I want the script to search the whole folder and any subfolders for that file extension and once it finds it then it will move the folder that contains that extension plus the extension.Here is what I have so far.
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\data'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
If objFile.Extension = "doc" Then
strCopy = "D:\Officedata\" & objFile.FileName _
& "." & objFile.Extension
objFile.Copy(strCopy)
objFile.Delete
End If
If objFile.Extension = "xls" Then
strCopy = "D:\Officedata\" & objFile.FileName _
& "." & objFile.Extension
objFile.Copy(strCopy)
objFile.Delete
End If
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='C:\data'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile in colFiles
If objFile.Extension = "doc" Then
strCopy = "D:\Officedata\" & objFile.FileName _
& "." & objFile.Extension
objFile.Copy(strCopy)
objFile.Delete
End If
If objFile.Extension = "xls" Then
strCopy = "D:\Officedata\" & objFile.FileName _
& "." & objFile.Extension
objFile.Copy(strCopy)
objFile.Delete
End If
Next