Funcion comparar archivos by STX / Seritx!
Publicado: 15 Abr 2012, 16:54
Dejo esta pequeña funcion inspirada en el comparador de Slek, gracias a Fake por enesima vez!
Devuelve 3 opciones: Archivos iguales o diferentes y el porcentage de comparacion (mas alto, mas parecidos).
Como no espero vuestras criticas!
Código: Seleccionar todo
function comparar(arc1 : String; arc2 : String) : String;
var
a, b : TextFile;
c, d, g : string;
e, f, h, pctg : Integer;
begin
pctg := 0;
Result := '';
AssignFile(a, arc1);
AssignFile(b, arc2);
Reset(a);
Reset(b);
Read(a, c);
Read(b, d);
closefile(a);
closefile(b);
e := Length(c);
f := Length(d);
If e = f then
g := 'Los dos archivos tienen el mismo tamaño.';
begin
For h := 0 to e do begin
If copy(c, h + 1, 1) = copy(d, h + 1, 1) then begin
pctg := pctg + 1;
end;
end;
end;
if e < f then
begin
g := 'El segundo archivo es más grande por: ' + inttostr(f - e) + ' bytes.';
for h := 0 to e do
begin
If copy(c, h + 1, 1) = copy(d, h + 1, 1) then pctg := pctg + 1;
end;
end;
if e > f then
begin
g := 'El primer archivo es más grande por: ' + inttostr(e - f) + ' bytes.';
for h := 0 to f do
begin
If copy(c, h + 1, 1) = copy(d, h + 1, 1) then pctg := pctg + 1;
end;
end;
pctg := ((pctg * 100) * 2) div (e + f);
Result := g + ' Porcentaje de comparacion: ' + inttostr(pctg) + '%';
end;
Como no espero vuestras criticas!