我有一个脚本可以修改.net应用程序中的web.config customErrors标签以及我之后运行的另一个脚本,以检查并确保所有标签都已更改。我的问题是第一个脚本创建了web.config的副本并将其命名为web.config-old。现在当我运行我的第二个脚本(下面的代码)时,如果找到所有web.config-old文件并将它们写入logoutput文件。如何确保它只查看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"
答案 0 :(得分:0)
您应该将文件的.Name与常量“web.config”进行比较(=),而不是使用Instr():
>> 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 ..”中的pos 1有'web.config',但'web.config'不等于“web.config..whatever ..”)