Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace String is not working on D drive 1

Status
Not open for further replies.

daksri

Programmer
Dec 16, 2010
3
0
0
CA
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
 
Define "not working". Do you get an error? if so on what line?
 
No errors. Nothing is happening. But If change the Directory Name to C:\DAK_TEST and place all the files, it is fine. Do I have to add change directory somewhere ?
 
If it works on one local drive, no reason why it shouldn't work on another local drive.
1) No typos? D:\DAK_TEST definitely exists?
2) Permissions are ok?
3) What's in "errResult" each time it renames a file?
 
I am good now. There was permission issue. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top