4/16/2008

vbscript to check each line in a file if there are included keywords defined in another file

  1. Dim objSourceFile, objKeywordFile, objNewFile, objFSO  
  2. Dim currentline, currentvariable, bIncluded  
  3.   
  4. Set objFSO =  CreateObject("Scripting.FileSystemObject")  
  5. Set objSourceFile = objFSO.OpenTextFile("D:\sourcefile.txt")  
  6. Set objKeywordFile = objFSO.OpenTextFile("D:\keywordfile.txt")  
  7. Set objNewFile = objFSO.CreateTextFile("D:\result.txt")  
  8. bIncluded = False  
  9.   
  10.   
  11. Do While Not objSourceFile.AtEndOfStream  
  12.  currentline = objSourceFile.ReadLine  
  13.  Call CheckIfIncluded  
  14. Loop  
  15.   
  16.   
  17.   
  18. Function CheckIfIncluded  
  19.   
  20.  Do While Not objKeywordFile.AtEndOfStream  
  21.   currentvariable = objKeywordFile.ReadLine  
  22.   
  23.   If InStr(currentline,currentvariable) Then  
  24.    bIncluded = False  
  25.    Exit Do  
  26.   Else  
  27.    bIncluded = True  
  28.   End If  
  29.  Loop  
  30.  If bIncluded = True Then  
  31.   objNewFile.WriteLine currentline  
  32.  End If  
  33.  Set objKeywordFile = Nothing  
  34.  Set objKeywordFile = objFSO.OpenTextFile("D:\variablefile.txt")  
  35.   
  36. End Function