Title: How to check a file name against a list of masks
uses
SysUtils, Masks; // works only from Delphi 5 and above
function isFileFromDefinition(aFilename, aMaskList: string): Boolean;
var
Definition: string;
begin
aFilename := ExtractFileName(aFilename);
Definition := '';
repeat
if Pos(';', aMaskList) 0 then
Definition := Copy(aMaskList, 1,Pos(';', aMaskList) - 1)
else
Definition := aMaskList;
Delete(aMaskList, 1,Length(Definition) + 1);
if MatchesMask(aFileName, Definition) then
begin
Result := True;
Exit;
end;
until Length(aMaskList) = 0;
Result := False;
end;
Usage Example:
isFileFromDefinition('c:\pictures\vanessa.jpg','*.gif;*.jpg;*.tga;*.bmp');
ifFileFromDefinition('c:\pictures\vanessa.jpg','v*.jp?');