03-03-2010, 12:06 PM
[COLOR="black"]لاستحضار قائمة المجلدات الفرعية من مجلد رئيسي:
مثال البحث عن الملفات:
بالتوفيق.[/COLOR]
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;
اللهم احقن دماء المسلمين، لا تنسوهم بالدعاء...

