蓝田县初级中学贺媛:对比二个文件并把不同之处输出

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 16:59:35
我知道winXP下自带的CMD程序可以使用FC命令对比二个文件并把不同之处输出,但我想知道如何把相同之外输出啊?好像CMD无能为力,是不是可以编个程序?

以下使用vb(qb)中 简单的方法解决此问题:
加入 InputF1,InputF2 是两个需要比较的文件 OutputF是输出文件那么

dim InputStr1 as string * 1
dim InputStr2 as string * 1

open InputF1 for binary as #1 len=1
open InputF2 for binary as #2 len=1
open OutputF for binary as #3 len=1

if Lof(1)>lof(2) then FileLens=lof(2) else FileLens=lof(1)

for TmpI=1 to FileLens

get #1,Tmpi,InputStr1
get #21,TmpI,InputStr2

if InputStr1=InputStr2 then
put #3,Tmpi,InputStr1
end if
next

close

这样就可以了

推荐使用UltraEdit-32软件
可以比较两文件

UltraEdit32