So I am working on some code that will eliminate a word that is found on a text file.
For example, I have a file with some lines, and in one of those lines the word "Update" exists, it will remove that whole line. The words to remove is picked up from a text file with many words that I want to remove.
The code right now read the line from the "remove.txt" file and compares it to the "file.txt" file, and if the word is not found it writes that line to a variable. After the loop is done, it goes ahead and writes all the strings in the variable, then sets the variable to nothing, and goes to compare the second word in the "remove.txt" file.
The code somewhat works, but takes a long long time to go through. Can anyone help me make this code a little better.
For example, I have a file with some lines, and in one of those lines the word "Update" exists, it will remove that whole line. The words to remove is picked up from a text file with many words that I want to remove.
The code right now read the line from the "remove.txt" file and compares it to the "file.txt" file, and if the word is not found it writes that line to a variable. After the loop is done, it goes ahead and writes all the strings in the variable, then sets the variable to nothing, and goes to compare the second word in the "remove.txt" file.
The code somewhat works, but takes a long long time to go through. Can anyone help me make this code a little better.
Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set txtFile1 = objfso.OpenTextFile(".\remove.txt", ForReading)
Do Until txtFile1.AtEndOfStream
Set strLine1 = CreateObject("VBScript.RegExp")
strLine1 = txtFile1.Readline
Set txtFile2 = objfso.OpenTextFile(".\file.txt", ForReading)
Do Until txtFile2.AtEndOfStream
strLine2 = txtFile2.Readline
If InStr(strLine2, strLine1) = 0 Then
strNewContents = strNewContents & strLine2 & vbCrLf
End If
Loop
txtFile2.Close
Set txtFile2 = objFSO.OpenTextFile(".\file.txt", ForWriting)
txtFile2.Write strNewContents
txtFile2.Close
strNewContents = nothing
Loop
txtFile1.Close