Bueno, logré esto:
Código Delphi
[-]
program listador;
{$APPTYPE CONSOLE}
uses Windows, SysUtils;
var
Txt: TextFile;
Nivel: Integer;
Function Espacios(Cantidad: Integer): String;
var
S: String;
begin
S:='';
While Cantidad>0 do
begin
S:=S+' ';
Dec(Cantidad);
end;
Result:=S;
end;
Procedure Lista(Ruta: String);
var
R: Integer;
Info: TSearchRec;
begin
R:=FindFirst(Ruta + '*', faDirectory, Info);
while R=0 do
begin
If not (Info.Name[1]='.') then begin
WriteLn(Espacios(Nivel) + '|- ' + Info.Name);
WriteLn(Txt, Espacios(Nivel) + '|- ' + Info.Name);
Inc(Nivel);
Lista(Ruta+Info.Name+'\');
Dec(Nivel);
end;
R:=FindNext(Info);
end;
FindClose(Info);
R:=FindFirst(Ruta + '*', faAnyFile, Info);
while R=0 do
begin
WriteLn(Espacios(Nivel) + '|- ' + Info.Name + ' [Tamaño: ' + IntToStr(Info.Size) + ' Bytes]');
WriteLn(Txt, Espacios(Nivel) + '|- ' + Info.Name + ' [Tamaño: ' + IntToStr(Info.Size) + ' Bytes]');
R:=FindNext(Info);
end;
FindClose(Info);
end;
begin
Nivel:=0;
AssignFile(Txt, ParamStr(2));
Rewrite(Txt);
Lista(ParamStr(1));
CloseFile(Txt);
end.
Pero tiene dos fallos. El primero es que al listar los directorios también lista los archivos. El segundo es que, al listar los archivos... ¡también aparecen los directorios!
¿Alguien sabe por qué pasa eso?
Salu2.
P.D.: También faltaría retocar el código un poco para que el árbol quede más bonito.