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 test if a string is a valid file name 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
15-Sep-02
Category
Files Operation
Language
Delphi All Versions
Views
91
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: William Gerbert

Test if a string is a valid file name

Answer:

The following code tests a given string for forbidden characters. The forbidden 
characters are dependent on whether it is a 8.3 (short) or a long file name. 


1   const
2     { for short 8.3 file names }
3     ShortForbiddenChars: set of Char = [';', '=', '+', '<', '>', '|',
4     '"', '[', ']', '\', ''''];
5     { for long file names }
6     LongForbiddenChars: set of Char = ['<', '>', '|', '"', '\'];
7   
8   function TestFilename(Filename: string; islong: Boolean): Boolean;
9   var
10    I: integer;
11  begin
12    Result := Filename <> '';
13    if islong then
14    begin
15      for I := 1 to Length(Filename) do
16        Result := Result and not (Filename[I] in LongForbiddenChars);
17    end
18    else
19    begin
20      for I := 1 to Length(Filename) do
21        Result := Result and not (Filename[I] in ShortForbiddenChars);
22    end;
23  end;


			
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