Ver Mensaje Individual
  #8  
Antiguo 15-02-2007
[basti] basti is offline
Miembro Premium
 
Registrado: ago 2004
Posts: 388
Reputación: 20
basti Va por buen camino
Trabajar con archivos de texto y blockread, es algo complicado, se me ocurre algo así, pero no sé si el rendimiento será superior al modelo con StringList:

Código Delphi [-]
  const
     MAX_REC_READ = 32000; // por ejemplo


  // copia aproximadamente los bytes de MAX_REC_READ
  // devuelve si no ha podido copiar todos
  function CopyFile(var forg, fdest : file) : boolean;
  var
    bytesLeidos : integer;
    buffer: array[1..MAX_REC_READ] of byte;
    bEOL : byte;

  begin
    Result := true;
    BlockRead(forg, buffer, MAX_REC_READ, bytesLeidos);
    BlockWrite(fdest, buffer, bytesLeidos);
    if bytesLeidos = MAX_REC_READ then // buscamos hasta el final del registro
    begin
       repeat
          BlockRead(forg, bEOL, 1, bytesLeidos);
          BlockWrite(fdest, bEOL, bytesLeidos);
       until eof(forg) or (bEOL = 10) // cambiar por 13 si el final de línea es sólo con #13;

    end
    else Result := false;
  end;

// programa principal
var
  forg, fdest : File;
  i : integer;
begin
  AssignFile(forg, 'origen.txt');
  Reset(forg, 1);
  i := 0;
  AssignFile(fdest, 'destino' + IntToStr(i) + '.txt');
  rewrite(fdest, 1);
  while CopyFile(forg, fdest) do
  begin
    CloseFile(fdest);
    inc(i);
    AssignFile(fdest, 'destino' + IntToStr(i) + '.txt');
    rewrite(fdest, 1);
  end;
  CloseFile(fdest);
  CloseFile(forg);
end.
Responder Con Cita