为简单起见,file1.txt是一个日志文件,我将logonIds提取到该日志文件中。 File2.txt包含logonID,emailAddress,其他,不需要的数据行
我需要将所有从file1读取的登录ID都从我的数组中读取,并从file2中提取其电子邮件地址。获得这些信息后,我就可以向file1中的每个人发送电子邮件。无法仅使用file2.txt,因为它包含不应接收电子邮件的用户。
我写了vbscript,它从file1.txt中提取登录ID到数组中,并从file2.txt中提取登录ID和电子邮件
inFile1 = "C:\Scripts\testvbs\wscreatestatus.txt"
inFile2 = "C:\Scripts\testvbs\WSBatchCreateBuildsList.txt"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile1 = objFSO.OpenTextFile(inFile1, ForReading)
Set objInFile2 = objFSO.OpenTextFile(inFile2, ForReading)
'Creates Array of all DomainIDs for successful deployments
Do Until objInFile1.AtEndOfStream
strNextLine = objInFile1.Readline
arrLogons = Split(strNextLine , vbTab)
If arrLogons(0) = "DEPLOYSUCCESS" Then
arrUserIDList = arrUserIDList & arrLogons(5) & vbCrLf
End If
Loop
Do Until objInFile2.AtEndOfStream
strNextLine = objInFile2.Readline
arrAddressList = Split(strNextLine , ",")
arrMailList = arrMailList & arrAddressList(0) & vbTab & arrAddressList(1) & vbCrLf
Loop
接下来,我需要获取用户ID列表“ arrUserIDList”,然后从arrMailList中提取其电子邮件地址。有了这些信息,我可以向file1.txt(wscreatestatus.txt)中的每个用户发送电子邮件。
谢谢!
答案 0 :(得分:0)
从构造arrMailList
的方式来看,我假设您希望将所选的LogonID和相应的电子邮件地址输出到新的制表符分隔的文本文件中。
如果是这种情况,我建议使用ArrayList对象存储值。ArrayLists具有易于使用的Add
方法,并且为了测试某项是否在ArrayList中,需要使用{{1} }方法。
在代码中:
Contains
希望有帮助
答案 1 :(得分:0)
这就是我解决问题的方式,但是我认为Theo采取了更好的方法。
Const ForReading = 1
Const ForWriting = 2
Dim inFile1, inFile2, strNextLine, arrServiceList, arrUserList
Dim arrUserDeployList, strLine, arrList, outFile, strItem1, strItem2
inFile1 = Wscript.Arguments.Item(0) 'wscreatestatus.txt file (tab delimited)
inFile2 = Wscript.Arguments.Item(1) 'WSBatchCreateBuildsList.txt (comma delimited)
outFile = Wscript.Arguments.Item(2) 'SuccessWSMailList###.txt (for Welcome emails)
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objInFile1 = objFSO.OpenTextFile(inFile1, ForReading)
Set objInFile2 = objFSO.OpenTextFile(inFile2, ForReading)
Set objOutFile = objFSO.CreateTextFile(outFile, ForWriting, True)
'Extracts Logon ID's for successfull deployments into an Array
'#================================================================
i = 0
Do Until objInFile1.AtEndOfStream
ReDim Preserve arrUsers(i)
strNextLine = objInFile1.Readline
arrLogons = Split(strNextLine , vbTab)
If arrLogons(0) = "PENDINGREQUESTS" Then
arrUsers(i) = arrLogons(5)
i = i + 1
End If
Loop
'Extracts success deploy email addresses and writes to file
'#================================================================
Do Until objInFile2.AtEndOfStream
ReDim Preserve arrMailList(i)
strNextLine = objInFile2.Readline
arrAddressList = Split(strNextLine , ",")
strItem1 = arrAddressList(0)
strItem2 = arrAddressList(1)
For Each strArrayEntry In arrUsers
If strArrayEntry = strItem1 Then
objOutFile.WriteLine strItem1 & "," & strItem2
End If
Next
i = i + 1
Loop
objOutFile.Close
objInFile1.Close
objInFile2.Close