469,592 Members | 1,713 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,592 developers. It's quick & easy.

System.IO, how to determine if valid path format

I have a small installation app that I'm building. The user can specify
an install path at the command line. How can I ensure that something
they put in is valid?

What I'm NOT looking for is determining if a path exists. I can
accomplish that with Directory.Exists(). I want them to put in a path
that may not exist and I'll create it for them.

What I AM looking for is making sure that the string is in the right
format like C:\Program Files\blah\blah\blah, not VDNSKVNKLSVNKNSVLKFNV

I suppose I could use a regular expression with no problem, but I was
wondering if there was anything in System.IO that would tell me that.
Sometimes the greatest solutions come from the simplest logic.
Being told "No" is merely the incentive to do it anyway.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 21 '05 #1
1 7766
In article <uH*************@TK2MSFTNGP11.phx.gbl>, WALDO wrote:
I have a small installation app that I'm building. The user can specify
an install path at the command line. How can I ensure that something
they put in is valid?

What I'm NOT looking for is determining if a path exists. I can
accomplish that with Directory.Exists(). I want them to put in a path
that may not exist and I'll create it for them.

What I AM looking for is making sure that the string is in the right
format like C:\Program Files\blah\blah\blah, not VDNSKVNKLSVNKNSVLKFNV

I suppose I could use a regular expression with no problem, but I was
wondering if there was anything in System.IO that would tell me that.
Sometimes the greatest solutions come from the simplest logic.
Being told "No" is merely the incentive to do it anyway.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


You could probably make use of the FolderBrowserDialog here - it lets
them create a new folder, and it would return a path...

Another way, might be to use the System.IO.Path class. If you call one
of it's methods with an illegal path (not necessarily an existing path)
it will throw an argument exception. So, you could just call it's
GetDirectoryName method which returns the directory part of the path. If
it's empty, only white space, or contains invalid characters, you'll get
an excpetion...

Function ValidPath (ByVal ThePath As String) As Boolean
Try
System.IO.Path.GetDirectoryName (ThePath)
Return True
Catch
Return False
End Try
End Function
--
Tom Shelton [MVP]
OS Name: Microsoft Windows XP Professional
OS Version: 5.1.2600 Service Pack 2 Build 2600
System Up Time: 32 Days, 1 Hours, 13 Minutes, 47 Seconds
Nov 21 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Penn Markham | last post: by
2 posts views Thread by vince | last post: by
4 posts views Thread by raibeart | last post: by
1 post views Thread by nygiantswin2005 | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.