On Nov 21, 1:01 pm, "Academia" <academiaNOS... @a-znet.comwrote:
I'd like to check a string to see that it is a valid file name.
Is there a Like pattern or RegEx that can do that.
1) Just the file name with maybe an extension
2)A full path
An help for either of the above would be appreciated.
Well... That depends on what your trying to accomplish? If your
checking for existance, then there is always System.IO.File. Exists.
If your just checking to make sure that you have a potentially valid
file name, then you can use the System.IO.Path classes
GetInvalidFileN ameChars and GetInvalidPathC hars to get an array of
characters that are not allowed in a file name and path, then you
could check to make sure your file name doesn't contain any of those
characters, using the String.IndexOfA ny. If it returns anything other
then negative 1, then you have a bad filename:
dim bfc() as char = path.getinvalid filenamechars()
if filename.indexo fany(bfc) -1 then
' illegal file name
end if
--
Tom Shelton