Oggi vediamo un piccolo snippets delphi, una procedura che restituisce la lista di file e directory presenti in una cartella e che accetta i caratteri jolly, ecco la procedura e un piccolo esempio di come funziona…
procedure FindFiles (const Path: String;
Attr: Integer;
List: TStrings) ;
var
Res: TSearchRec;
EOFound: Boolean;
begin
EOFound:= False;
if FindFirst(Path, Attr, Res) < 0 then
exit
else
while not EOFound do begin
List.Add(Res.Name) ;
EOFound:= FindNext(Res) <> 0;
end;
FindClose(Res) ;
end;
// ListBox1 è un componente TListBox presente sul form, in alternativa si può usare TStringList...
FindFiles('C:\Windows\*.exe',faAnyFile,ListBox1.Items);

