كيفية البحث
#8
[COLOR="black"]لاستحضار قائمة المجلدات الفرعية من مجلد رئيسي:
PHP كود :
function Dir_CountDir(strPathName: String;bRecurseDir : Boolean):Integer;
    var
        
strTempPath : string;
        
nCount : integer;
        
hFindFile : THandle;
        
FindData : TWin32FindData;
    
Begin
        nCount 
:= 0;
        
Result := 0;
        
strTempPath := strPathName+'\*.*';
        
hFindFile := Windows.FindFirstFile(PChar(strTempPath),FindData);
        if 
hFindFile = INVALID_HANDLE_VALUE then Exit;
        
repeat
            
if (IsChildDir(FindData)) then
            begin
                nCount 
:= nCount+1;
                if 
bRecurseDir then
                begin
                    strTempPath 
:= strPathName+'\'+FindData.cFileName;
                    nCount := nCount+Dir_CountDir(strTempPath,bRecurseDir);
                end;
            end;
        until (not Windows.FindNextFile(hFindFile,FindData));
        Windows.FindClose(hFindFile);
        Result := nCount;
    end;

    function IsChildDir (var lpFindData : TWin32FindData) : Boolean;
    var
        b : boolean;
    begin
        Result := ((lpFindData.dwFileAttributes and FILE_ATTRIBUTE_DIRECTORY) <>0);
        b := (lpFindData.cFileName[0] <> '
.');
        Result := (Result and b);
    end; 
مثال البحث عن الملفات:
PHP كود :
procedure FindFiles(FilesList: TStringList; StartDir, FileMask: string);
var
   
SR: TSearchRec;
   
DirList: TStringList;
   
IsFound: Boolean;
   
i: integer;
begin
     
if StartDir[length(StartDir)] <> '\' then StartDir := StartDir + '\';

     // Build a list of the files in directory StartDir

     IsFound := FindFirst(StartDir + FileMask, faAnyFile-faDirectory, SR) = 0;
     while IsFound do
     begin
          FilesList.Add(StartDir + SR.Name);
          IsFound := FindNext(SR) = 0;
     end;
     FindClose(SR);

     // Build a list of subdirectories
     DirList := TStringList.Create;
     IsFound := FindFirst(StartDir+'
*.*', faAnyFile, SR) = 0;
     while IsFound do
     begin
          if ((SR.Attr and faDirectory) <> 0) and (SR.Name[1] <> '
.') then
             DirList.Add(StartDir + SR.Name);
          IsFound := FindNext(SR) = 0;
     end;
     FindClose(SR);

     // Scan the list of subdirectories
     for i := 0 to DirList.Count - 1 do
         FindFiles(FilesList, DirList[i], FileMask);

         DirList.Free;
end;

(* -----------------
   Example:
----------------- *)

procedure TForm1.ButtonFindClick(Sender: TObject);
var
   FilesList: TStringList;
begin
     FilesList := TStringList.Create;
     try
        FindFiles(FilesList, EditStartDir.Text, EditFileMask.Text);
        ListBox1.Items.Assign(FilesList);
        LabelCount.Caption := '
Files found: ' + IntToStr(FilesList.Count);
     finally
            FilesList.Free;
     end;
end; 
بالتوفيق.[/COLOR]
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...
الرد


الردود في هذا الموضوع
كيفية البحث - بواسطة houssin - 15-05-2009, 07:02 PM
كيفية البحث - بواسطة mohfa - 15-05-2009, 07:33 PM
كيفية البحث - بواسطة houssin - 17-05-2009, 06:51 PM
كيفية البحث - بواسطة محمد عبد العزيز - 17-05-2009, 08:19 PM
كيفية البحث - بواسطة MjIrIm - 02-03-2010, 01:09 PM
كيفية البحث - بواسطة abdelmalek - 03-03-2010, 10:43 AM
كيفية البحث - بواسطة abdelmalek - 03-03-2010, 11:21 AM
كيفية البحث - بواسطة kachwahed - 03-03-2010, 12:06 PM
كيفية البحث - بواسطة mohfa - 03-03-2010, 12:40 PM
كيفية البحث - بواسطة abdelmalek - 03-03-2010, 01:35 PM
كيفية البحث - بواسطة abdelmalek - 05-03-2010, 08:45 AM
كيفية البحث - بواسطة abdelmalek - 27-06-2010, 11:06 AM
كيفية البحث - بواسطة Benhlell - 30-06-2010, 09:03 AM
كيفية البحث - بواسطة FPS - 17-12-2011, 10:37 PM
كيفية البحث - بواسطة FPS - 18-12-2011, 07:05 PM

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


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