help with VBscript and renaming files
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.
Any help would be appreciated, I am just starting out with VB, finally moving away from Kix!
Thanks
Jimmy
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
Answers (3)
Please log in to answer
Posted by:
aogilmor
16 years ago
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
Posted by:
anonymous_9363
16 years ago
Posted by:
jimmyx
16 years ago
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
Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
so that the conversation will remain readable.