Board index » delphi » A {*word*218} question on Filename routines

A {*word*218} question on Filename routines

Hello,

Does anyone know if there is a platform independent function that will
make sure a given filename is valid or not?

ie. to make sure there are no *, or ?, or /, or \, or :, or control
characters in it?

Just wanted to know before I went ahead and wrote one.

Thanks,
Roger

 

Re:A {*word*218} question on Filename routines


Quote
> Does anyone know if there is a platform independent function that will
> make sure a given filename is valid or not?

> ie. to make sure there are no *, or ?, or /, or \, or :, or control
> characters in it?

I wrote this one a long time ago ...

function IsValidFileName(const FileName: string): Boolean;
begin
  Result := (FileName <> '') and
            (not HasAnyChar(FileName, '/*?<>"|')) and
            (Pos('\', ExtractFileName(FileName)) = 0) and
            (Pos(':', ExtractFileName(FileName)) = 0);
end;

Hope this will help

Julien

Re:A {*word*218} question on Filename routines


On Thu, 19 Dec 2002 19:44:43 +0400 in alt.comp.lang.borland-delphi,

Quote
"Julien Ferraro" <jfk_...@netcourrier.com> wrote:

>> Does anyone know if there is a platform independent function that will
>> make sure a given filename is valid or not?

>> ie. to make sure there are no *, or ?, or /, or \, or :, or control
>> characters in it?

>I wrote this one a long time ago ...

>function IsValidFileName(const FileName: string): Boolean;
>begin
>  Result := (FileName <> '') and
>            (not HasAnyChar(FileName, '/*?<>"|')) and
>            (Pos('\', ExtractFileName(FileName)) = 0) and
>            (Pos(':', ExtractFileName(FileName)) = 0);
>end;

>Hope this will help

>Julien

That's excellent. Thanks Julien.

Other Threads