Steph's procedure will work perfectly, but I thought it worth the effort to give you my procedure, and it can handle searching subdirectories too:
var
l : TStringList;
procedure SearchTree(APath, ASpec: String; const ASub: Boolean = True);
var
f : TSearchRec;
begin
APath := IncludeTrailingPathDelimiter(APath);
if FindFirst(APath + ASpec, faAnyfile, f) = 0 then
repeat
if f.Name[1] = '.' then Continue;
if ((f.Attr and faDirectory) <> 0) and ASub then
SearchTree(APath + f.Name, ASpec, ASub)
else
l.Add(APath + f.Name);
until FindNext(f) <> 0;
FindClose(f);
end;
That's it. Initialise your TStringList prior to calling the procedure, and it will contain the complete folder and filenames of the matching files. If you set ASub to False it won't go into any subfolders.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.