Ver Mensaje Individual
  #4  
Antiguo 15-02-2007
Avatar de seoane
[seoane] seoane is offline
Miembro Premium
 
Registrado: feb 2004
Ubicación: A Coruña, España
Posts: 3.717
Reputación: 24
seoane Va por buen camino
Efectivamente egostar, parece que la instrucción FileSize no funciona muy bien con los archivos de texto. Pero todo tiene solución:

Código Delphi [-]
var
  Str: String;
  Source, Dest: TextFile;
  Size: Integer;
  F: File;
begin
  Size:= 0;
  // Abrimos el archivo sin tipo para averiguar su tamaño en bytes
  AssignFile(F,'C:\Origen.txt');
  {$I-}
    Reset(F,1);
  {$I+}
  if IOResult = 0 then
  begin
    Size:= FileSize(F) div 2;
    CloseFile(F);
  end;
  // Ahora abrimos el archivo como texto
  AssignFile(Source,'C:\Origen.txt');
  {$I-}
    Reset(Source);
  {$I+}
  if IOResult = 0 then
  begin
    // Creamos el primer trozo
    AssignFile(Dest,'C:\Trozo1.txt');
    {$I-}
      Rewrite(Dest);
    {$I+}
    if IOResult = 0 then
    begin
      while (not Eof(Source)) and (Size > 0) do
      begin
        Readln(Source,Str);
        Writeln(Dest,Str);
        dec(Size,Length(Str)+2);
      end;
      CloseFile(Dest);
    end;
    // Creamos el segundo trozo
    AssignFile(Dest,'C:\Trozo2.txt');
    {$I-}
      Rewrite(Dest);
    {$I+}
    if IOResult = 0 then
    begin
      while not Eof(Source) do
      begin
        Readln(Source,Str);
        Writeln(Dest,Str);
      end;
      CloseFile(Dest);
    end;
    CloseFile(Source);
  end
end;
Responder Con Cita