Search in absolute file name web.config and not all files that start with web.configxxxx

116 views Asked by At

I have a script that modifies the web.config customErrors Tags in a .net application and another script I run afterwards to check and ensure all tags have been changed. My issues is the fist script creates a copy of the web.config and names it web.config-old. Now when I run my second script(the code below) if finds all the web.config-old files and writes them to the logoutput file. How can I ensure that it will only look in Web.config and no the backup copy. I guess to summarize I need to only look in the absolute filename of Web.config and none other. thanks in advance.

Sub ShowSubFolders(Folder)
Dim strToFind, strToFind1
Dim fso, f
strToFind = "customErrors mode=""Off"""
strToFind1= "compilation debug=""true"""
On Error Resume Next
For Each Subfolder in Folder.SubFolders 
Set objFolder = objFSO.GetFolder(Subfolder.Path) 
Set colFiles = objFolder.Files 
    for each Files in colFiles 
        if LCase(InStr(1,Files, "Web.config")) > 1 then 

Set objFSO1 = CreateObject("Scripting.FileSystemObject")
    Set objFile1 = objFSO.OpenTextFile(Files, 1)

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.OpenTextFile(pwd & "\CheckWebConf.txt", ForAppending, True)
strText = objFile1.ReadAll
objFile1.close

If InStr(strText, strToFind) > 0 Then
pos = InStrRev(Files,"\domains\") + 1 
        MyString = mid(Files, pos)
    f.WriteLine MyString & " Found Error mode=Off  "

    Else
End If
   If InStr(strText, strToFind1) > 0 Then
pos = InStrRev(Files,"\domains\") + 1 
        MyString = mid(Files, pos)
    f.WriteLine MyString & " Found debug=true " 

    Else
  End If
 f.close

 end if

            next

    ShowSubFolders Subfolder 

Next

End Sub

 msgbox "Done"
1

There are 1 answers

2
Ekkehard.Horner On

Instead of using Instr() you should compare (=) the file's .Name with the constant "web.config":

>> For Each s In Split("web.config web.configx")
>>     WScript.Echo s, "InStr", CStr(1 = Instr(s, "web.config"))
>>     WScript.Echo s, "Equal", CStr(s = "web.config")
>>     WScript.Echo
>> Next
>>
web.config InStr True
web.config Equal True

web.configx InStr True
web.configx Equal False

(There is a 'web.config' at pos 1 in "web.config..whatever..", but 'web.config' is not equal to "web.config..whatever..")