|
我需要在教本里比较两个文本文件(XM文件)的内容是否一致,就偷懒写了个简单的VBS的脚本:
// 比较两个文本文件(文件名)
Public Function CompTwoFiles(FileName1,FileName2)
Const ForReading = 1, ForWriting = 2, ForAppending = 8,vbTextCompare =1
Dim fso1, obj_file1,fso2, obj_file2
Dim FileContents1, FileContents2
Set fso1 = CreateObject("Scripting.FileSystemObject")
Set obj_file1 = fso1.OpenTextFile(FileName1, ForReading)
FileContents1 = obj_file1.ReadAll
Set fso2 = CreateObject("Scripting.FileSystemObject")
Set obj_file2 = fso2.OpenTextFile(FileName2, ForReading)
FileContents2 = obj_file2.ReadAll
obj_file1.Close
obj_file2.Close
CompTwoFiles= StrComp(FileContents1,FileContents2,vbTextCompare)
End Function
一方面直接share给大家,另外有更好的办法做到比较两个文本文件吗? |
|