Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing 2 Text Files

Status
Not open for further replies.

NickC111

Technical User
Sep 23, 2010
44
GB
Good Morning

I have this script below that compares FILE1 and FILE2 - any differences are written to the results.txt.

The only problem I have is if a new entry is added to FILE2 then the script doesn't write the new entry to the results. It only works if an entry is missing from FILE2 compared to FILE1.

Any Ideas?

Thanks

Set fso=CreateObject("Scripting.FileSystemObject")

Set txtfile=fso_OpenTextFile("FILE1.txt")

data=txtfile.readAll

txtfile.close

txtArray=split(data,vbCRLF)

Set txtfile=fso_OpenTextFile("FILE22.txt")

data=txtfile.readAll

txtfile.close

dim list

for n=0 to ubound(txtArray)

if instr(data,txtArray(n))=0 then list=list & txtArray(n) & vbCRLF

next

Set txtfile=fso.CreateTextFile("RESULTS.txt")

txtfile.write list

txtfile.close
 
Here is a recent thread dealing with a similar problem: thread329-1634108
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top