' Constants for filesystem object
Const ForReading = 1
Const ForWriting = 2
Const TriStateUseDefault = -2
' Input file to be checked and possibly replaced
strFile = "B:\EE\EE29071385\myfile.txt"
' Line number in file to check
intLine = 14
' Search array, with phrase to match on line and file to copy when match found
arrReplace = Array(Array("this is a cat", "B:\EE\EE29071385\cat\myfile.txt"), _
Array("this is a dog", "B:\EE\EE29071385\dog\myfile.txt"))
' Creaet filesystem object
Set objFSO = CreateObject("Scripting.FileSystemObject")
' Read input file into memory
Set objFile = objFSO.OpenTextFile(strFile, ForReading, False, TriStateUseDefault)
strData = objFile.ReadAll
objFile.Close
' Split into temp array at line breaks
arrData = Split(strData, vbCrLf)
' If less lines than the one we need to check, exit now
If UBound(arrData) < (intLine-1) Then
Wscript.Quit
End If
' Check each search phrase and if match found copy corresponding file
For Each arrMatch In arrReplace
If LCase(arrMatch(0)) = LCase(arrData(intLine-1)) Then
objFSO.CopyFile arrMatch(1), strFile
End If
Next
And you want to read file1, look at a specific line (is that located by line number, or some other way?).
And then depending on some or all of the content on that line in file1, you want to replace that line with something from either file2 or file3?
What gets selected from file2 / file3, is it the same line number, the whole file, etc?
And do you want to overwrite the original file1 when done, or create a new file4?
Can you please provide samples of the three files, and the expected result of the script.
»bp