1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Read txt file and compar with files in folder then copy files compared to folder2 VBS

Discussion in 'Visual Basic ( VB )' started by jallloh, Oct 17, 2011.

  1. jallloh

    jallloh New Member

    Joined:
    Oct 17, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    I'm trying to make my script read a text file which has numbers on each row, then it should compare the text file with some file names that are in a folder, finally its copies the file names it compare with the text file to a another folder.
    I'm still learning how to script, so I hope someone out there can help.

    Thanks

    Code:
    Const ForReading = 1
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objTextFile = objFSO.OpenTextFile _
        ("c:\mytest1\test.txt", ForReading)
    Do Until objTextFile.AtEndOfStream
        strNextLine = objTextFile.Readline
        arrServiceList = Split(strNextLine , ",")
        Wscript.Echo "Server name: " & arrServiceList(0)
        For i = 1 to Ubound(arrServiceList)
            Wscript.Echo "Service: " & arrServiceList(i)
        Next
        Set objFSO = CreateObject("Scripting.FileSystemObject")
    
    If arrServiceList("C:\test1\*.pdf") Then
        objFSO.CopyFile "C:\test1\*.pdf,  "C:\test2\"
    Else
        Wscript.Echo "The file does not exist."
    End If
    Loop
     
    Last edited by a moderator: Oct 18, 2011

Share This Page