Ver Mensaje Individual
  #3  
Antiguo 31-01-2009
jorge82 jorge82 is offline
Baneado
 
Registrado: jun 2005
Ubicación: Mérida, Yucatán, México
Posts: 75
Reputación: 19
jorge82 Va por buen camino
Hola, esta función recorre el directorio pasado como parámetro y lista los archivos y directorios, además lleva la cuenta de ellos, al final guarda la lista en un StringList, por lo que facilmente puedes asignar su contenido en un TMemo o componente similar.

Código Delphi [-]
procedure Contar(SPath: string);
var
  R : TSearchRec;
  Busq, Dirs, Arcs: Integer;
  List: TStringList;
begin
  Dirs :=0; Arcs := 0;
  List := TStringList.Create;

  if not DirectoryExists(SPath) then
  begin
    Application.MessageBox(PChar('No existe la ruta: ' + SPath), 'Error', MB_ICONERROR);
    Exit;
  end;

  Busq := FindFirst(SPath + '*.*', FaAnyfile, R);
  while Busq = 0 do
  begin
    if (R.Attr and faDirectory = faDirectory ) then
    begin
      if (R.Name <> '.') and (R.Name <> '..') then
      begin
        Inc(Dirs);
        List.Add(R.Name + '/');
      end;
    end
    else
    begin
      if (R.Attr and faVolumeId <> faVolumeID) then
      begin
        Inc(Arcs);
        List.Add(R.Name);
      end;
    end;
    Busq := FindNext(R);
  end;
  SysUtils.FindClose(R);
  Form1.Memo1.Lines := List;
  List.Free;
  ShowMEssage(Format('Hay %d Directorios y %d Archivos', [Dirs, Arcs]));
end;

Ejemplo de llamada:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  Contar('C:\');
end;

Espero que te sirva.
__________________
Un saludito.
Responder Con Cita