阅读背景:

对比两个文件是否相同的函数

来源:互联网 
function CompFile(const f1,f2: string): Boolean;
var
  ms1,ms2: TMemoryStream;
  i,p: Integer;
  b1,b2: Byte;
begin
  Result := False;
  if not (FileExists(f1) and FileExists(f2)) then Exit;

  ms1 := TMemoryStream.Create;
  ms2 := TMemoryStream.Create;

  ms1.LoadFromFile(f1);
  ms2.LoadFromFile(f2);

  if ms1.Size <> ms2.Size then
  begin
    ms1.Free;
    ms2.Free;
    Exit;
  end;

  Result := True;
  Randomize;
  for i := 0 to 9 do
  begin
    p := Random(ms1.Size);
    ms1.Position := p;
    ms2.Position := p;
    ms1.ReadBuffer(b1,1);
    ms2.ReadBuffer(b2,1);
    if b1 <> b2 then
    begin
      Result := False;
      Break;
    end;
  end;

  ms1.Free;
  ms2.Free;
end;

 
 
 
  function CompFile(const f1,f2: string): Boolean



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: