0

我有一个脚本可以修改 .net 应用程序中的 web.config customErrors 标签,然后我运行另一个脚本来检查并确保所有标签都已更改。我的问题是第一个脚本创建了 web.config 的副本并将其命名为 web.config-old。现在,当我运行我的第二个脚本(下面的代码)时,如果找到所有 web.config-old 文件并将它们写入日志输出文件。我怎样才能确保它只会在 Web.config 中查找而没有备份副本。我想总结一下,我只需要查看 Web.config 的绝对文件名即可。提前致谢。

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"
4

1 回答 1

0

而不是使用 Instr() 您应该将文件的 .Name 与常量“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

(“web.config..whatever..”的位置 1 有一个“web.config”,但“web.config”不等于“web.config..whatever..”)

于 2013-12-05T15:34:17.527 回答