|
|
Title | See if a directory exists in VB .NET |
Description | This example shows how to see if a directory exists in Visual Basic .NET. |
Keywords | directory exists, directory, exists |
Categories | VB.NET, Files and Directories |
|
|
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
|
|
There's lots more information about VB 2005 in my book Visual Basic 2005 Programmer's Reference.
|
|
|
|
|
|