Ver Mensaje Individual
  #1  
Antiguo 23-09-2011
Taburiente Taburiente is offline
Miembro
 
Registrado: may 2006
Posts: 26
Reputación: 0
Taburiente Va por buen camino
Ficheros texto II

Hola de nuevo,

En unos post anteriores prometí a ecfisa ponerme las pilas en el tratamiento de ficheros planos y en ello estoy.

Os cuento mi nuevo problema y que no se como solventar. Partiendo de un fichero origen necesito extraer entre otras, las lineas que contenga la palabra "L_CODE" sin las comillas, en origen estan asi:

Código:
#MSG_3 L_CODE 7 193407869 4e7b50cb	22/09/2011_17:14:00
#MSG_5 L_CODE 9 193418949 4e7b50cf	22/09/2011_17:14:00
#MSG_6 L_CODE 8 193409660 4e7b50d2	22/09/2011_17:14:00
y en mi fichero destino me salen asi:

Código:
L_CODE 7 193407869 4e7b50cb	22/09/2011_17:14:00
L_CODE 9 193418949 4e7b50cf	22/09/2011_17:14:00
L_CODE 8 193409660 4e7b50d2	22/09/2011_17:14:00
y yo lo que necesito es que me salga de esta manera:

Código:
193407869 	22/09/2011_17:14:00
193418949 	22/09/2011_17:14:00
193409660 	22/09/2011_17:14:00
Y mi codigo hasta ahora es:

Código Delphi [-]
procedure GenerarArchivos(const Ruta: string; const Nombre: string);
var
  p: integer;
  i: integer;
  Str: String;
  Origen, Destino: TextFile;
  Linea: string;

begin
     AssignFile(Origen,Ruta+Nombre);
     Reset(Origen);
     AssignFile(Destino,Ruta+Copy(ExtractFileName(Linea),1,Length(Linea)-3)+'.kcl');
  {$I-}
    Reset(Origen);
  {$I+}
  if IOResult = 0 then
  begin
     Rewrite(Destino);
    {$I+}
    if IOResult = 0 then
    begin
      while not Eof(Origen) do
      begin
       Readln(Origen,Str);
        //Readln(Origen,Linea);

        i:= Pos('M_COUNT',Uppercase(Str));
         p:= Pos('L_CODE',Uppercase(Str));
        if i > 0 then
          Writeln(Destino,Copy(Str,i,MAXINT));
           if p > 0 then
          Writeln(Destino,Copy(Str,p,MAXINT));
      end;
      CloseFile(Destino);
    end;
     CloseFile(Origen);
     ShowMessage('PROCESO TERMINADO'+#13+#13+'Ficheros generados en...'+#13+Ruta);
  end;
end;

BEGIN
 Button1.Enabled := false;
  try
  OpenDialog.InitialDir := ExtractFilePath(Application.ExeName);
  if OpenDialog.Execute then
  begin
    if FileExists(OpenDialog.FileName) then
    begin
      Screen.Cursor := crHourGlass;
      try
        GenerarArchivos(ExtractFilePath(OpenDialog.FileName), ExtractFileName(OpenDialog.FileName));
      finally
        Screen.Cursor := crDefault;
      end;
    end;
  end
  else
    ShowMessage('Cancelado por el usuario');
  finally
  Button1.Enabled := true;
  end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 Close;
end;

end.

Por favor, podría decirme alguien como conseguir lo que necesito.

Gracias anticipadas

Saludos

Última edición por ecfisa fecha: 23-09-2011 a las 19:25:26.
Responder Con Cita