用于在文件中搜索的VBscript

用于在文件中搜索的VBscript,vbscript,Vbscript,我是一个vbscript新手,想搜索通过ftp下载的一些文件。我运行了一个下载文件的脚本,现在我不知道如何运行该脚本来搜索所有文件。这就是我所拥有的,但我认为我应该使用select case语句 抱歉,如果这个代码看起来很粗糙 Sub ReadDownloads() Dim strInput As String strInput = "file\path\somefile.ftp" Dim dhigh, dclose, dlow Close #1 Open strInput For Inp

我是一个vbscript新手,想搜索通过ftp下载的一些文件。我运行了一个下载文件的脚本,现在我不知道如何运行该脚本来搜索所有文件。这就是我所拥有的,但我认为我应该使用select case语句

抱歉,如果这个代码看起来很粗糙

Sub ReadDownloads()

Dim strInput As String
strInput = "file\path\somefile.ftp"

Dim dhigh, dclose, dlow

Close #1
Open strInput For Input As #1

  Input #1, strReadLine
  Input #1, strReadLine


While Not EOF(1)
    Input #1, strReadLine
    'Debug.Print strReadLine
    arrbreakdown = Split(strReadLine, " ")
    'Debug.Print arrbreakdown(1)
    If Left(arrbreakdown(1), 7) = "itemsearchingfor" Then
        If Mid(arrbreakdown(1), 8, 1) = "c" Then
            dclose = arrbreakdown(3)
        ElseIf Mid(arrbreakdown(1), 8, 1) = "h" Then
            dhigh = arrbreakdown(3)
        ElseIf Mid(arrbreakdown(1), 8, 1) = "l" Then
            dlow = arrbreakdown(3)
        End If
    End If


Wend
Close #1

Debug.Print dclose
Debug.Print dhigh
Debug.Print dlow

Range("D2").Value = dclose
Range("E2").Value = dhigh

如果您希望在文件中搜索文本。第一步是将文件转换成字符串

如下所示的函数将为您执行此操作:

' -----------------------------------------
Private Function getFileAsString(p_strFilePath)
    Dim objFSO, objFile
    Dim strFileContents

    Set objFSO = CreateObject("Scripting.FileSystemObject") 
    Set objFile = objFSO.OpenTextFile(p_strFilePath, 1, false) 
    strFileContents = objFile.ReadAll 

    'clean up
    Set objFSO = Nothing
    Set objFile = Nothing

    getFileAsString = strFileContents
End Function    
下一步是检查字符串中是否存在文本,即文件内容

下面的函数将为您实现这一点,它使用VB
InStr
函数,返回文本显示次数的整数

' ----------------------------------------- 
Public Function isTextPresent(p_strFileContents)
    Dim intTemp, blnTextFound

    'using 'InStr' function to see if a string exists  
    intTemp = InStr (p_strFileContents, "WHATEVER TEXT YOU ARE SEARCHING FOR")

    If intTemp > 0 Then
        blnTextFound = True
    Else
        blnTextFound = False
    End If    

    isTextPresent = blnTextFound
End Function

这是VBA或VB6代码,它们与VBScript的语言不同。谢谢,这是一个很大的帮助。我不确定的一件事是如何搜索多个文件。我需要搜索四个文件。我已经通过ftp下载了它们。我在文件中有几个不同的词要搜索。我应该将这些文件放入一个数组中,然后遍历这些文件吗。使用case语句。