سلام
از اين كد براي جستجوي فايلها در پوشه ها و زير پوشه ها مي توني استفاه كني. براي استفاده يه tmemo به فرمتون اضافه كنيد تا نتايج اونجا نمايش داده بشن. مقدار برگشتي از تابع، تعداد فايلهاي پيدا شده است:
کد:
function findfiles(const path, mask: String; includesubdir: Boolean): Integer;
var
findresult: Integer;
searchrec : Tsearchrec;
begin
result := 0;
findresult := findfirst(path + mask, faanyfile - fadirectory, searchrec);
while findresult = 0 do
begin
{ do whatever you'd like to do with the files found }
form1.memo1.lines.add(path + searchrec.name);
result := result + 1;
findresult := findnext(searchrec);
end;
{ free memory }
findclose(searchrec);
if not includesubdir then
exit;
findresult := findfirst(path + '*.*', fadirectory, searchrec);
while findresult = 0 do
begin
if (searchrec.name <> '.') and (searchrec.name <> '..') then
result := result +
findfiles (path + searchrec.name + '\', mask, true);
findresult := findnext(searchrec);
end;
{ free memory }
findclose(searchrec);
end;
نحوه فراخواني ( براي مثال، يافتن كليه فايلهاي mp3 در كليه پوشه ها و زير پوشه هاي درايو "جي":
کد:
var
founditem:integer;
begin
founditem:=findfiles('g:\','*.mp3',true);
if founditem<>0 then
showmessage(inttostr(founditem)+' item found')
else
showmessage('no item found');
end;
موفق باشيد