Home All Groups Group Topic Archive Search About
Author
7 Jun 2006 6:37 PM
Brahm
Hi Folks,

    do you know a file name validator ?

    I am reading a text file and I am creating new files in runtime. In some
cases it is found string with invalid characters so. I
  have errors.

    I was able to avoid the problem with this character "/"

Is there anything peace of code already ready for this ?

Any help is appreciated.

Thanks.

Author
7 Jun 2006 7:37 PM
Ken Tucker [MVP]
Hi,

       Use a regular expression.

dim rFile as new
regex([A-Z]:\\[^/:\*\?<>\|]+\.\w{2,6})|(\\{2}[^/:\*\?<>\|]+\.\w{2,6})")
if rFile.isMatch(strFilename) then
           'you have a valid file name
end if
http://search.msdn.microsoft.com/search/default.aspx?siteId=0&tab=0&query=regex

Ken
-------------------------
Show quoteHide quote
"Brahm" wrote:

> Hi Folks,
>
>     do you know a file name validator ?
>
>     I am reading a text file and I am creating new files in runtime. In some
> cases it is found string with invalid characters so. I
>   have errors.
>
>     I was able to avoid the problem with this character "/"
>
>  Is there anything peace of code already ready for this ?
>
> Any help is appreciated.
>
> Thanks.
>
>
>
Author
7 Jun 2006 8:35 PM
Kerry Moorman
Brahm,

You can use the System.IO.Path class.

Path.GetFileName will throw an exception if the filename contains invalid
characters.

Kerry Moorman


Show quoteHide quote
"Brahm" wrote:

> Hi Folks,
>
>     do you know a file name validator ?
>
>     I am reading a text file and I am creating new files in runtime. In some
> cases it is found string with invalid characters so. I
>   have errors.
>
>     I was able to avoid the problem with this character "/"
>
>  Is there anything peace of code already ready for this ?
>
> Any help is appreciated.
>
> Thanks.
>
>
>