Results 1 to 3 of 3

Thread: [RESOLVED] [2008] Detect if a path is in a valid format

  1. #1

    Thread Starter
    Addicted Member AnthonyGrimes's Avatar
    Join Date
    Sep 2008
    Location
    United States
    Posts
    131

    Resolved [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.

  2. #2
    Addicted Member Dark Anima's Avatar
    Join Date
    Sep 2008
    Posts
    183

    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

  3. #3

    Thread Starter
    Addicted Member AnthonyGrimes's Avatar
    Join Date
    Sep 2008
    Location
    United States
    Posts
    131

    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
  •  



Click Here to Expand Forum to Full Width