Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Test if a string is a valid file name
6 comments. Current rating: (3 votes). Leave comments and/ or rate it.
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.
Thanks to a comment to A. Pottjeweid, who pointed out that the forward slash is a problem character as well.
 | |  | | const
ShortForbiddenChars : set of Char = [';', '=', '+', '<', '>', '|',
'"', '[', ']', '\', '/', ''''];
LongForbiddenChars : set of Char = ['<', '>', '|', '"', '\', '/', ':', '*', '?'];
function TestFilename(Filename: String; islong: Boolean) : Boolean;
var
I: integer;
begin
Result := Filename <> '';
if islong then
begin
for I := 1 to Length(Filename) do
Result := Result and not (Filename[I] in LongForbiddenChars);
end
else
begin
for I := 1 to Length(Filename) do
Result := Result and not (Filename[I] in ShortForbiddenChars);
end;
end;
| |  | |  |
Comments:
|
hungpvtn@gmail.com from Australia
|
|
|
|
LongForbiddenChars : set of Char = ['<', '>', '|', ''', '', '/',':','*','?'];
|
|
anonymous from Madrid in Madrid, Spain
|
|
|
|
Here is good website!!! I will introduce it to my friends...
|
|
anonymous from Sønderborg in Sonderjylland, Denmark
|
 |
|
|
|
|
Vahid from Iran, Iran
|
 |
|
|
usefull :) TNX
|
|
anonymous from Ukraine
|
 |
|
|
thanks for code
|
|
anonymous from Australia
|
|
|
|
|
|