Hi All
I am trying to rename any instance of filename "tnsnames.ora" on a system to "tnsnames.old" the code below renames the file in a particular location OK.

I am getting stuck with adding in a wildcard so all the files are renamed.

strComputer = "."
Set objWMIService = GetObject _
("winmgmts:" & "!\\" & strComputer & "\root\cimv2")
Set colFiles = objWMIService.ExecQuery _
("Select * from Cim_Datafile where Name = " _
& "'C:\\tnsnames\\tnsnames.ora'")
For Each objFile in colfiles
errResult = objFile.Rename("C:\tnsnames\tnsnames.old")
Wscript.Echo errResult
Next


Any help would be appreciated, I am just starting out with VB, finally moving away from Kix!

Thanks
Jimmy
0 Comments   [ + ] Show Comments

Comments

Please log in to comment

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.

Answers

0
Jimmy, look up cim_datafile on microsoft's web site. I think you'll find you can't include the entire path in the Name. You'll have to structure your query to look on your desired drive, or all drives, and the Name is a separate field from Extension. The Scripting guys have a couple of scripts that do similar things to wha you want. Google them too, they're on msft. Good luck, Owen
Answered 11/21/2008 by: aogilmor
Ninth Degree Black Belt

Please log in to comment
0
I agree. Stick with the FileSystemObject, er, object. There are innumerable scripts around which will recurse through a folder. You can then edit it to take any action(s) you want on files found therein.
Answered 11/21/2008 by: VBScab
Red Belt

Please log in to comment
0
Thanks for your guidance guys, I have got the renaming part of the script working now here it is for info:


strComputer = "."

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")

Set colFiles = objWMIService.ExecQuery _
("Select * From CIM_DataFile Where FileName = 'tnsnames' and Extension = 'ora'")

For Each objFile in colFiles
Wscript.Echo objFile.Name
strNewName = objFile.Drive & objFile.Path & "tnsnames.old"
errResult = objFile.Rename(strNewName)

Next

Answered 11/24/2008 by: jimmyx
Purple Belt

Please log in to comment
Answer this question or Comment on this question for clarity