function GetFilesEx(sPath, sExtensions:
String;
var sdaFiles: tStringDynArray;
IncludeSubdirectories: Boolean): Boolean;
var
I: Word;
sdaMasks: tStringDynArray;
Predicate: tDirectory.TFilterPredicate;
begin
Result := False;
if (sPath = '
')
or
(
not tDirectory.Exists(sPath))
then begin
ShowMsg('
ungültiger Pfad', '
GetFilesEx', mb_OK, mb_IconInformation);
Exit;
end;
sPath := IncludeTrailingPathDelimiter(sPath);
if sExtensions = '
'
then begin
ShowMsg('
ungültige Dateierweiterung(en)', '
GetFilesEx', mb_OK,
mb_IconInformation);
Exit;
end;
sdaMasks := SplitString(sExtensions, '
;');
for I := 0
to High(sdaMasks)
do begin
if Pos('
.', sdaMasks[I]) = 1
then sdaMasks[I] := '
*' + sdaMasks[I]
else if Pos('
*.', sdaMasks[I]) = 0
then sdaMasks[I] := '
*.' + sdaMasks[I];
end;
Predicate :=
function(
const Path:
string;
const SearchRec: TSearchRec): Boolean
var
Mask:
String;
begin
for Mask
in sdaMasks
do
if MatchesMask(SearchRec.
Name, Mask)
then Exit(True);
Exit(False);
end;
try
if IncludeSubDirectories
then
sdaFiles := tDirectory.GetFiles(sPath, TSearchOption.soAllDirectories,
Predicate)
else sdaFiles := tDirectory.GetFiles(sPath, Predicate);
Result := True;
except
on E:
Exception do begin
ShowMsg(E.
Message, '
GetFilesEx', mb_OK, mb_IconError);
end;
end;
end;