472,364 Members | 1,878 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,364 software developers and data experts.

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 7855
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: vince | last post by:
MSDN help says you can use a UNC path for any methods that accept a path, and I'm wondering if I can also substitute an IP address for the UNC....??? Example: Using System.IO.File.Move() ...
14
by: Jon Davis | last post by:
I have put my users through so much crap with this bug it is an absolute shame. I have a product that reads/writes RSS 2.0 documents, among other things. The RSS 2.0 spec mandates an en-US style...
3
by: karunakar | last post by:
Hi All Here iam getting this Error "Specified cast is not valid." My Project has Onc solution diffrent class libarary In that solution DALfactory solution iam getting this error I was calling...
3
by: Patrick.O.Ige | last post by:
I'm loading an Array below but getting the error "Object reference not set to an instance saying 'ItemNumber = CType(Args.Item.FindControl("ItemNumber"), TextBox).Text' is the error line. I DON'T...
6
by: Don | last post by:
I'm having problems working with a streamwriter object. After closing the streamwriter and setting it to Nothing, I try to delete the file it was writing to, but I always get the following error...
4
by: raibeart | last post by:
I am trying to use System.IO.File.Exists to determine if a file exiusts on a server. I am using a UNC path stored in a database table. Is there a way to use UNC rather than a mapped drive? For...
3
by: Phoe6 | last post by:
Hi all, I had a filesystem crash and when I retrieved the data back the files had random names without extension. I decided to write a script to determine the file extension and create a newfile...
1
by: nygiantswin2005 | last post by:
Hi I am trying to resolve this bug that I have in this application. The code is below. It will generate this Exception System.UnauthorizedAccessException: Access to the path is denied. at...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific technical details, Gmail likely implements measures...
1
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web server and have made sure to enable curl. I get a...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
0
BLUEPANDA
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
0
by: Rahul1995seven | last post by:
Introduction: In the realm of programming languages, Python has emerged as a powerhouse. With its simplicity, versatility, and robustness, Python has gained popularity among beginners and experts...
1
by: ezappsrUS | last post by:
Hi, I wonder if someone knows where I am going wrong below. I have a continuous form and two labels where only one would be visible depending on the checkbox being checked or not. Below is the...
0
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.