|
-
Dec 2nd, 2008, 12:47 PM
#1
Thread Starter
Addicted Member
[RESOLVED] [2008] Detect if a path is in a valid format
Sorry if this is a simple question, but here it goes. I have a program that allows a user to either select a output filename or manually type the output filename. Is there any way to check if the path\filename are in the proper format? Since it may not exist yet, I am trying to check if it is a valid format (ie C:\Whatever\Whatever.abc) before I create the new file.
Would I have to check each piece for existance? The drive letter (C:\), the folder (C:\Whatever) and that the filename has an extension, even if not valid.
I was just wondering if there is anything easier.
Thanks for any input.
Last edited by AnthonyGrimes; Dec 2nd, 2008 at 01:00 PM.
-
Dec 2nd, 2008, 01:16 PM
#2
Addicted Member
Re: [2008] Detect if a path is in a valid format
You could do it by checking if the directory exists (something like If System.Directory.Exists("C:\Whatever\") = True Then everything's alright)
But couldn't you just use a simple Try / Catch there?
Code:
Private Sub SaveFile()
Try
Dim ObjWriter As New System.IO.StreamWriter("C:\Whatever\abc.text")
Catch ex As Exception
MsgBox("Invalid path")
End Try
End Sub
-
Dec 2nd, 2008, 01:19 PM
#3
Thread Starter
Addicted Member
Re: [2008] Detect if a path is in a valid format
I will give that a shot. Thank you for your response.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|