See if a directory exists in VB .NET

Started by nandagopal, Nov 17, 2008, 07:01 PM

Previous topic - Next topic

nandagopal

The System.IO.Directory.Exists method returns True if a file exists.


Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load
    Dim dir_name As String = Application.StartupPath
    If System.IO.Directory.Exists(dir_name) Then
        lblDir1.Text = dir_name & " exists"
    Else
        lblDir1.Text = dir_name & " does not exist"
    End If

    dir_name = dir_name.Substring(0, _
        dir_name.LastIndexOf("\")) & "\Missing"
    If System.IO.Directory.Exists(dir_name) Then
        lblDir2.Text = dir_name & " exists"
    Else
        lblDir2.Text = dir_name & " does not exist"
    End If
End Sub