Cita:
Empezado por coso
deberías usar recursividad...
|
Gracias, me inspiré en su idea y escribí el siguiente código (requiere: Form1, OpenDialog1, Button1):
Código Delphi
[-]unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
public
end;
function LeerArchivo(namefile: String; destino: TStringList): Boolean;
var
Form1: TForm1;
sPath: String;
implementation
{$R *.dfm}
procedure ParseToken(tok: String; destino: TStringList);
begin
tok := TrimLeft(tok);
if (Pos('INCLUDE',tok)<>0) then begin
Delete(tok, 1, 7);
tok := TrimLeft(tok);
tok := AnsiDequotedStr(tok, '"');
LeerArchivo(sPath+tok, destino);
end
else destino.Add(tok);
end;
function LeerArchivo(namefile: String; destino: TStringList): Boolean;
var
st: TStringList;
i, r: Longint;
tok: String;
begin
st := TStringList.Create;
st.LoadFromFile(namefile);
r := st.Count;
for i:=0 to r-1 do begin
tok := st[i];
ParseToken(tok, destino);
end;
st.Free;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
dest: TStringList;
begin
dest := TStringList.Create;
if OpenDialog1.Execute then begin
sPath := ExtractFilePath(OpenDialog1.FileName);
LeerArchivo(OpenDialog1.FileName, dest);
dest.SaveToFile('ArchivoFinal.txt');
end;
dest.Free;
end;
end.
... para hacerlo funcionar, clic en el botón y elegir "Archivo1.txt" (mencionado arriba) y auto se creará "ArchivoFinal.txt" con todas las líneas de los INCLUDE.
Ahora, con esta misma idea no sería mejor hacerlo directamente con AssignFile etc etc?... Digo esto porque lo de crear StringList me parece consumo de memoria y tiempo?... (imaginando archivos de texto de tamaño medio ~200KB).
Iluminarme si me equivoco.
Gracias de antemano.
- Gaak -