HasValidFileNameChars fails for UNC files

432 views Asked by At

For me HasValidFileNameChars function (in Delphi XE7) returns false for UNC files:

B:= IOUtils.TPath.HasValidFileNameChars('\\ETA-PC\tests\test.ini', FALSE)          
B is false now

This means that if you try to validate the filename that I show in my test (yes the file is real and as you can see its name is correct) HasValidFileNameChars will fail. HasValidPathChars work!
Is this normal?

- Edit:

In the Help page, the first parameter is named 'path'. Which made me believe that the function will accept full paths.

Quote:

 Name        Meaning         
 Path        The verified file name string.
2

There are 2 answers

0
Jan Doggen On BEST ANSWER

Use HasValidPathChars instead of HasValidFileNameChars. A file name cannot contain the backslash.

0
David Heffernan On

The function behaves correctly because a \ is not a valid character for a file name. It is the path separator.

The distinction here is between file names and paths. Using your example, \\ETA-PC\tests\test.ini is a path, but the file name is test.ini.

I suspect that you are looking for HasValidPathChars.