Quantcast
Channel: VBForums - ASP, VB Script
Viewing all articles
Browse latest Browse all 686

Search for a sting in text files Merge those text files

$
0
0
Hello,
I am having a little trouble. Here is what I am trying to do.
Search all text files in a folder for a string
If that string is found than merge those text files that were found.
Any help to point me in the right direction would be great.
I am having no problem with the search for string part

Code:

Set colFiles = objFolder.Files
For Each objFile in colFiles
    'Wscript.Echo objFile.Name
    strFile = "\\path to folder\" & objFile.Name
    set objFile = objFSO.getFile(strFile)
    if objFile.size > 0 then
        If InStr(oFSO.OpenTextFile(strFile).ReadAll, strSearchFor) > 0 Then
          filesys.CopyFile "\\path to folder\" & objFile.Name, "\\path to folder\" & "Name_"& strDate &".txt"
        Else
            WScript.Sleep (100)
        END If
    END If
Next

The above code searches for the needed string and copies the file to a new name. But only for one file. I have more than one file with the search string in it and need to merge all files with the search string in them.

Thank you

Viewing all articles
Browse latest Browse all 686

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>