procedure TFindFiles.Find(
Handle: THandle; RootFolder:
string; Mask:
string; Recurse: Boolean = True);
var
hFindFile : THandle;
wfd : TWin32FindData;
begin
if FFTerminate
then
Exit;
Inc(FLevel);
if RootFolder[length(RootFolder)] <> '
\'
then
RootFolder := RootFolder + '
\';
ZeroMemory(@wfd, sizeof(wfd));
wfd.dwFileAttributes := FILE_ATTRIBUTE_NORMAL;
if Recurse
then
begin
hFindFile := FindFirstFile(pointer(RootFolder + '
*.*'), wfd);
if hFindFile <> 0
then
try
repeat
if wfd.dwFileAttributes
and FILE_ATTRIBUTE_DIRECTORY = FILE_ATTRIBUTE_DIRECTORY
then
begin
if (
string(wfd.cFileName) <> '
.')
and (
string(wfd.cFileName) <> '
..')
then
begin
SendMessage(
Handle, FFM_ONDIRFOUND, FLevel, lParam(
string(RootFolder + wfd.cFileName)));
Find(
Handle, RootFolder + [b]wfd.cFileName[/b], Mask, Recurse);
end;
end;
until FindNextFile(hFindFile, wfd) = False;
Inc(FiFolder);
SendMessage(
Handle, FFM_PROGRESS, FiFolder, 0);
finally
Windows.FindClose(hFindFile);
end;
end;
hFindFile := FindFirstFile(pointer(RootFolder + Mask), wfd);
if hFindFile <> INVALID_HANDLE_VALUE
then
try
repeat
if (wfd.dwFileAttributes
and FILE_ATTRIBUTE_DIRECTORY <> FILE_ATTRIBUTE_DIRECTORY)
then
begin
SendMessage(
Handle, FFM_ONFILEFOUND, 0, lParam(
string(RootFolder + [b]wfd.cFileName[/b])));
end;
until FindNextFile(hFindFile, wfd) = False;
finally
Windows.FindClose(hFindFile);
end;
Dec(FLevel);
end;