PDA

Ver la Versión Completa : Filtro en delphi


edribalo
02-02-2016, 20:02:39
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
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 (http://www.clubdelphi.com/foros/guiaestilo.php).

Intenta de este modo:

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:

procedure TForm1.Button1Click(Sender: TObject);
begin
FindFiles(Edit1.Text, '.DPR', Memo1.Lines);
end;


Saludos :)