Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Varios (https://www.clubdelphi.com/foros/forumdisplay.php?f=11)
-   -   Filtro en delphi (https://www.clubdelphi.com/foros/showthread.php?t=89763)

edribalo 02-02-2016 20:02:39

Filtro en delphi
 
Disculpen queria saber si alguien me podia a ayudar a filtar archivos que solo me impriman los .dpr en el memo aqui les dejo el codigo
Código Delphi [-]
procedure FindFiles(StartDir:string);
const
  //MASK = '*.dpr';
  CHAR_POINT = '.';
var
  SR: TSearchRec;
  DirList: TStringList;
  IsFound: Boolean;
  i: integer;
begin

  if (StartDir[length(StartDir)] <> '\') then
  begin
    StartDir := StartDir + '\';
  end;

  // Crear la lista de ficheos en el dir. StartDir (no directorios!)
  IsFound := FindFirst(StartDir + '*', faDirectory, SR) = 0;

  DirList := TStringList.Create();

  // MIentras encuentre
  while IsFound do
  begin
    if(SR.Name <> '.') and (SR.Name <> '..') then
    begin
        DirList.Add(StartDir + SR.Name);
        ShowMessage(StartDir + SR.Name);
        FindFiles(StartDir + SR.Name);
    end;
    IsFound := FindNext(SR) = 0;
  end;

  FindClose(SR);
end;

procedure TForm1.btn1Click(Sender: TObject);
var
  sl : TStringList;
begin
 sl := TStringList.Create;
 FindFiles(edt1.Text);
 ESBMemo1.Lines.Text:= sl.GetText;
end;

end.

ecfisa 02-02-2016 21:52:56

Hola edribalo, bienvenido a los foros de Club Delphi :)

Como a todos los que ingresan, te invitamos a que leas nuestra guía de estilo.

Intenta de este modo:
Código Delphi [-]
procedure FindFiles(Folder: string; const Extension :string; TS: TStrings);
var
  SR: TSearchRec;
  Found: Boolean;
begin
  Screen.Cursor := crHourGlass;
  try
    Folder := IncludeTrailingPathDelimiter(Folder);
    if FindFirst(Folder + '*.*', faDirectory, SR) = 0 then
    repeat
      Found := UpperCase(ExtractFileExt(SR.Name)) = UpperCase(Extension);
      if ((SR.Attr and fadirectory) = fadirectory) then
      begin
        if(SR.Name <> '.') and (SR.Name <> '..') then
        begin
          if Found then
            TS.Add(Folder + SR.Name );
          FindFiles(Folder + SR.Name, Extension, TS)
        end
      end
      else if Found then
        TS.Add(Folder + SR.Name);
    until FindNext(SR) <> 0;
    FindClose(SR);
  finally
    Screen.Cursor := crDefault;
  end;
end;

Llamada ejemplo:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
begin
  FindFiles(Edit1.Text, '.DPR', Memo1.Lines);
end;

Saludos :)


La franja horaria es GMT +2. Ahora son las 07:26:58.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi