I have this script below that works on the C: drive just fine. It does not work on the D: drive at all.
Basically it searches a folder root and sub folders for file types of .trace. Once it finds them it renames the extension to a .txt . I am not sure why it does not like the D:. It is probably pretty simple.
strComputer = "."
strFolderRoot = "D:\Test 2\"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '" & Replace(strFolderRoot, "\", "\\") & "%'")
For Each objFolder in colFolders
strTMP = Replace(Mid(objFolder.Name,4,Len(objFolder.Name)),"\","\\")
strQuery = "SELECT * FROM CIM_DATAFILE WHERE Drive = D:' " & _
"AND Path = '\\" & strTMP & "\\'"
Set colFiles = objWMIService.ExecQuery(strQuery)
For Each objFile In colFiles
MsgBox objFile.Extension
If objFile.Extension = "trace" Then
strNewName = objFile.Drive & objFile.Path & _
objFile.FileName & "." & "txt"
errResult = objFile.Rename(strNewName)
Wscript.Echo errResult
End If
Next
Next
MsgBox "Done
Basically it searches a folder root and sub folders for file types of .trace. Once it finds them it renames the extension to a .txt . I am not sure why it does not like the D:. It is probably pretty simple.
strComputer = "."
strFolderRoot = "D:\Test 2\"
Set objWMIService = GetObject("winmgmts:" _
& "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colFolders = objWMIService.ExecQuery _
("Select * from Win32_Directory where Name Like '" & Replace(strFolderRoot, "\", "\\") & "%'")
For Each objFolder in colFolders
strTMP = Replace(Mid(objFolder.Name,4,Len(objFolder.Name)),"\","\\")
strQuery = "SELECT * FROM CIM_DATAFILE WHERE Drive = D:' " & _
"AND Path = '\\" & strTMP & "\\'"
Set colFiles = objWMIService.ExecQuery(strQuery)
For Each objFile In colFiles
MsgBox objFile.Extension
If objFile.Extension = "trace" Then
strNewName = objFile.Drive & objFile.Path & _
objFile.FileName & "." & "txt"
errResult = objFile.Rename(strNewName)
Wscript.Echo errResult
End If
Next
Next
MsgBox "Done