The function you are looking at already has a point at which it skips directories:
if not IsDotOrDotDot(cFileName) and
((soIncludeSystemHiddenDirs in Options) or not IsSystemAndHidden(FFindData)) then
So you can simply extend this condition. However, I would not extend it by adding another and
clause. I personally find if
statements like this to be exceedingly opaque. I would introduce an explanatory variable:
var
SkipDirectory: Boolean;
and then assign it like this:
if IsDotOrDotDot(cFileName) then
SkipDirectory := True
else if IsSystemAndHidden(FFindData) and not (soIncludeSystemHiddenDirs in Options) then
SkipDirectory := True
else if IsJunction(FFindData) then
SkipDirectory := True
else
SkipDirectory := False;
if not SkipDirectory then
....
And then you need to re-work your IsJunction
to receive a TWin32FindData
parameter:
function IsJunction(const FindData: TWin32FindData): Boolean;
const
IO_REPARSE_TAG_MOUNT_POINT = $0A0000003;
begin
Result := ((FindData.dwFileAttributes and FILE_ATTRIBUTE_REPARSE_POINT)
= FILE_ATTRIBUTE_REPARSE_POINT) and
(FindData.dwReserved0 = IO_REPARSE_TAG_MOUNT_POINT);
end;
Although I'd probably re-write @Sertac's if statement to break it up a bit more. But perhaps that's just my personal preference.
function FlagIsSet(Flags, Flag: DWORD): Boolean;
begin
Result := (Flags and Flag)<>0;
end;
function IsJunction(const FindData: TWin32FindData): Boolean;
const
IO_REPARSE_TAG_MOUNT_POINT = $0A0000003;
begin
Result := FlagIsSet(FindData.dwFileAttributes, FILE_ATTRIBUTE_REPARSE_POINT)
and (FindData.dwReserved0=IO_REPARSE_TAG_MOUNT_POINT);
end;