06-03-2015, 11:37 PM
هذا أخي إجراء يقوم بالبحث عن ملف في مجلد معين مع إمكانية البحث داخل المجلدات الفرعية وهو يستخدم فكرة استدعاء الدالة لنفسها Recursif وتقوم بوضع مسار الملف في listbox
طريقة الاستدعاء
RecSearch('c:\windows','File.dll', true);
كود :
procedure TForm14.RecSearch(const sPathName, sFile : String; const subDir : Boolean);
var
sr : TSearchRec;
sPath : String;
begin
Application.ProcessMessages;
sPath:=IncludeTrailingBackslash(sPathName);
if FindFirst(sPath + sFile, faAnyFile - faDirectory, sr) = 0 then
repeat
listBox1.Items.Add(sPath + sr.Name); // send files into a ListBox
until FindNext(sr) <> 0;
FindClose(sr);
If not subDir then Exit;
if FindFirst(sPath + '*.*', faDirectory, sr) = 0 then
repeat
if ((sr.Attr and faDirectory) <> 0) and (sr.Name<>'.') and (sr.Name<>'..') then
RecSearch(sPath + sr.Name, sFile, True);
until FindNext(sr) <> 0;
FindClose(sr);
end;طريقة الاستدعاء
RecSearch('c:\windows','File.dll', true);

