whats new ¦  programming tips ¦  indy articles ¦  intraweb articles ¦  informations ¦  links ¦  interviews
 misc ¦  tutorials ¦  Add&Win Game

Tips (1541)

Database (90)
Files (137)
Forms (107)
Graphic (114)
IDE (21)
Indy (5)
Internet / LAN (130)
IntraWeb (0)
Math (76)
Misc (126)
Multimedia (45)
Objects/
ActiveX (51)

OpenTools API (3)
Printing (35)
Strings (83)
System (266)
VCL (242)

Top15

Tips sort by
component


Search Tip

Add new Tip

Add&Win Game

Advertising

41 Visitors Online


 
... check a file name against a list of masks?
Autor: CutMaster
Homepage: http://www.wptechnology.com
[ Print tip ]  

Tip Rating (9):  
     


{
  This code can be used to test if the given filename matches with a
  list of wildcards search.

  examples of use :
  isFileFromDefinition('c:\pictures\vanessa.jpg','*.gif;*.jpg;*.tga;*.bmp');
  ifFileFromDefinition('c:\pictures\vanessa.jpg','v*.jp?');
}

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;


 

Rate this tip:

poor
very good


Copyright © by SwissDelphiCenter.ch
All trademarks are the sole property of their respective owners