Quantcast
Channel: Active questions tagged vbscript - Code Review Stack Exchange
Viewing all articles
Browse latest Browse all 32

Check if an XML file exists then change URLs in it

$
0
0

This is my first VBScript I have ever written and I would like to know if there is any obvious blunders in the code. All the code should do is check if file exists then change the Yahoo URL to the Google URL in the XML file. Note: The code seems to function properly.

Dim objFSOSet objFSO = CreateObject("Scripting.FileSystemObject")If (objFSO.FileExists("C:\urlsinfo.xml")) ThenConst ForReading = 1Const ForWriting = 2Const ForAppending = 8Dim textToReplaceDim textReplacementtextToReplace = "http://www.yahoo.com"textReplacement = "http://www.google.com"Set objFile = objFSO.OpenTextFile("C:\urlsinfo.xml", ForReading)strText = objFile.ReadAllobjFile.ClosestrNewText = Replace(strText, textToReplace, textReplacement)Set objFile = objFSO.OpenTextFile("C:\urlsinfo.xml", ForWriting)objFile.WriteLine strNewTextobjFile.CloseWScript.Quit()ElseDim errorFileSys, errorLogTxtSet errorFileSys = CreateObject("Scripting.FileSystemObject")Set errorLogTxt = errorFileSys.OpenTextFile("C:\urlsinfoError.log", ForAppending, True) errorLogTxt.WriteLine(Now &"     urlsinfo.xml file did not exist in directory C:\. ")errorLogTxt.CloseWScript.Quit()End If'Exit ScriptWScript.Quit()

Viewing all articles
Browse latest Browse all 32

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>