Searching files for a string with VBscript

Discussion in 'Visual Basic ( VB )' started by tekdatt, Apr 27, 2012.

  1. tekdatt

    tekdatt New Member

    Joined:
    Apr 27, 2012
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I need to make a script that searches all the text files in a folder for a specific string and if the file has that string, I need to save it do a different folder. I realize this may be a simple task for a real programmer, but I'm just a novice programmer. Please help. I've been able to figure out how to search a file for the string.

    Dim objFSO, strLine, objReadFile
    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Set objReadFile = objFSO.OpenTextFile("C:\temp\Test.txt", 1, False)

    Do Until objReadFile.AtEndOfStream

    strLine = objReadFile.ReadLine
    strLine = trim(strLine)

    if instr(strLine, "123456") Then
    'save this file to folder C:\temp\save\
    End If

    Loop

    set objFSO = nothing


    I'm just not understanding how to do it for every file in the folder, and once it finds the string, how to save it to the other folder.
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice