Ему походу надо работать не именами файлами, а с текстом, если не ошибаюсь.
Код:
//T - text; M - mask; Sp - StartPos; result - position (index) in text
//if Substr is not found, function returns zero.
function MatchesMaskEx(T, M: string; Sp: integer): integer;
var
Tl, Ml: integer; // length of file name and mask
Tp, Mp: integer; // pointers
first: boolean;
begin
T := UpperCase(T);
M := UpperCase(M);
result := 0;
Tl := length(T);
Ml := length(M);
Tp := Sp;
Mp := 1;
first := false;
while Mp <= Ml do
begin // wildcard
case M[Mp] of //
'?':
begin // if one any char
inc(Mp); // next char of mask
inc(Tp); // next char of file name
end; //
' * ':
begin // if any chars
if Mp = Ml then
exit; // if last char in mask then exit
if M[Mp + 1] = T[Tp] then
begin // if next char in mask equate char in
Inc(Mp); // file name then next char in mask and
end
else
begin // else
if Tp = Tl then
begin // if last char in file name then
result := 0; // function return false
exit; //
end; // else, if not previous, then
inc(Tp); // next char in file name
end; //
end; //
else
begin // other char in mask
if M[Mp] <> T[Tp] then
begin // if char in mask not equate char in
Mp := 1;
first := false;
continue;
end; // else
if (Mp = Ml) and (Tp <> Tl) then begin
Result := 0;
exit;
end;
if first = false then begin
first := true;
Result := Tp;
end;
inc(Tp); // next char of mask
inc(Mp); // next char of file name
end
end;
end;
end;