16,473
社区成员
发帖
与我相关
我的任务
分享
bool is_file_name_valid(const string &filename)
{
FILE *fp = fopen(filename.c_str(), "a+"); // filename包含路径
if ( fp )
fclose(fp);
return (fp != NULL);
}
const
{ for short 8.3 file names }
ShortForbiddenChars : set of Char = [';', '=', '+', '<', '>', '|',
'"', '[', ']', '\', '/', ''''];
{ for long file names }
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;