كيف البحث عن ملف في حالة عدم وجوده بالمسار
#5
هذا أخي إجراء يقوم بالبحث عن ملف في مجلد معين مع إمكانية البحث داخل المجلدات الفرعية وهو يستخدم فكرة استدعاء الدالة لنفسها Recursif وتقوم بوضع مسار الملف في listbox

كود :
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);
الرد


الردود في هذا الموضوع
كيف البحث عن ملف في حالة عدم وجوده بالمسار - بواسطة الكاسر الآخر - 06-03-2015, 11:37 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم