'how can we use all values str1,str2 under str1
path = "D:\verify\files\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set directory = fso.GetFolder(path).Files
For Each file In directory
If file.Attributes = "32" Then
Dim sSearchString1, sSearchString2, sSearchString3, sSearchString4, extension
sSearchString1 = "<IDNew>511</IDNew>"
sSearchString2 = "<Name>nielle</Name>"
sSearchString3 = " <IDNew>643</IDNew>"
sSearchString4 = "<Name>ase</Name>"
extension = "xml"
Set oFolder = fso.GetFolder(dir)
For Each fil In oFolder.Files
Set oFile = fso.OpenTextFile(fil.Path, ForReading)
strName1 = fso.GetFileName(fil)
sReadAll = oFile.ReadAll
oFile.Close
If InStr(sReadAll, sSearchString1) > 0 Or _
InStr(sReadAll, sSearchString2) > 0 Or _
InStr(sReadAll, sSearchString3) > 0 Or _
InStr(sReadAll, sSearchString4) > 0 Then
count = count+1
fso.CopyFile fil.Path, StrDestinationLocation
cap12 = " Backup Success"
strContent = "" & Date & Space(1) & sms & Space(1) & cap12 & Space(2) & strName1
Set objLogs = FSO.OpenTextFile(strFileName1, ForAppending, True)
objLogs.WriteLine(strContent)
objLogs.Close
End If
答案 0 :(得分:1)
您可能希望将支票放入如下函数中:
Function ContainsAny(txt, arr)
ContainsAny = False
For Each str In arr
If InStr(txt, str) > 0 Then
ContainsAny = True
Exit For
End If
Next
End Function
所以你可以测试你的输入:
sSeachString1 = Array("511", "nielle", ...)
For Each fil In oFolder.Files
sReadAll = fso.OpenTextFile(fil.Path, ForReading).ReadAll
If ContainsAny(sReadAll, sSearchString1) Then
'...
'copy file
'...
End If
Next