/build/static/layout/Breadcrumb_cap_w.png

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.

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)

Posted by: aogilmor 16 years ago
9th Degree Black Belt
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
Posted by: anonymous_9363 16 years ago
Red Belt
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.
Posted by: jimmyx 16 years ago
Purple Belt
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

Rating comments in this legacy AppDeploy message board thread won't reorder them,
so that the conversation will remain readable.
 
This website uses cookies. By continuing to use this site and/or clicking the "Accept" button you are providing consent Quest Software and its affiliates do NOT sell the Personal Data you provide to us either when you register on our websites or when you do business with us. For more information about our Privacy Policy and our data protection efforts, please visit GDPR-HQ