473,769 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.Exist s(). 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 VDNSKVNKLSVNKNS VLKFNV

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 7932
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.Exist s(). 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 VDNSKVNKLSVNKNS VLKFNV

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 FolderBrowserDi alog 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
GetDirectoryNam e 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. GetDirectoryNam e (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
4964
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 webserver runs that part of the script (see attached file, snippet.php), though, it doesn't go through. I don't get an error message or anything...it just returns a "1" (whereas it should return a "0") as far as I can tell. I have read the PHP...
2
7402
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() File.Move("\\\\MyServer\\share\\dir\\myfile.txt", "\\\\YourServer\\share\\dir\\myfile.txt");
14
3689
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 of date formatting (RFC 822). I have been using a variation of RFC 1123 (just change the time zone to an offset, i.e. "-0800"). It seems to be writing okay, but it's failing to parse. I've tried changing the regional & language settings in my...
3
8231
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 this function in DALFactory class library(this library generate the DAL.dll) Another class library has this function public SecurityInfo Login(string username, string password) {
3
4152
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 KNOW WHAT I'M DOING WRONG I USED ASP.NETWebMatrix and its working well!! Any help!! I have declared ItemNumber as u can see below " :-
6
10217
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 message: "The process cannot access the file "whatever" because it is being used by another process." I've even tried opening another file using the same streamwriter object before deleting the original file, but it's no use. Something keeps...
4
15049
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 example: \\Srv09\Data\LogCenter\Logs\log_1.tif will not work x:\LogCenter\Logs\log_1.tif will work Thanks in advance.
3
9118
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 with extension. --- method 1: # File extension utility. import os
1
4603
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 System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath) at System.IO.__Error.WinIOError() at System.IO.FileInfo.MoveTo(String destFileName)
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10208
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10038
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9987
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7404
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
1
3952
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.