The following script is working on C drive, but not in D drive. (D is a local drive - NOT a Mapped drive). Any idea ?
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='D:\DAK_TEST'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & "txt"
If Instr(1, strNewName, "Policy_") > 0 Or Instr(1, strNewName, "POLICY_") > 0 Then
strNewName = Replace(strNewName, "POLICY_", "")
End If
errResult = objFile.Rename(UCase(strNewName))
Next
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set FileList = objWMIService.ExecQuery _
("ASSOCIATORS OF {Win32_Directory.Name='D:\DAK_TEST'} Where " _
& "ResultClass = CIM_DataFile")
For Each objFile In FileList
strNewName = objFile.Drive & objFile.Path & objFile.FileName & "." & "txt"
If Instr(1, strNewName, "Policy_") > 0 Or Instr(1, strNewName, "POLICY_") > 0 Then
strNewName = Replace(strNewName, "POLICY_", "")
End If
errResult = objFile.Rename(UCase(strNewName))
Next