Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
.How to determining if a file name matches a specification Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
22-May-03
Category
Files Operation
Language
Delphi 3.x
Views
99
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Ernesto De Spirito

How can I know if a file name matches a specification with wildcards?

Answer:

Sometimes we need to know if a file name matches a file specification (a name with 
wildcards: '?' and '*'). Here we implement a function that returns True if the 
given file name matches a specification and False if not. 
1   
2   function MatchesSpec(const FileName,
3     Specification: string): boolean;
4   var
5     SName, SExt, FName, FExt: string;
6   begin
7     FName := ExtractFileName(FileName);
8     SName := ExtractFileName(Specification);
9     FExt := ExtractFileExt(FName);
10    SExt := ExtractFileExt(SName);
11    SetLength(FName, Length(FName) - Length(FExt));
12    SetLength(SName, Length(SName) - Length(SExt));
13    if SName = '' then
14      SName := '*';
15    if SExt = '' then
16      SExt := '.*';
17    if FExt = '' then
18      FExt := '.';
19    Result := Like(FName, SName) and Like(FExt, SExt);
20  end;


NOTE: The Like function has been featured in my article  
"Determining if a string matches a pattern with wildcards ('?' and 
'*')dkb://542874283" 

Sample call 

21  if MatchesSpec('Document1.doc', 'DOC*.DO?') then
22    ShowMessage('It worked!');


Copyright (c) 2001 Ernesto De Spiritomailto:edspirito@latiumsoftware.com
Visit: http://www.latiumsoftware.com/delphi-newsletter.php

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC