This documentation is archived and is not being maintained.

How to: Determine if a Directory Exists in Visual Basic

You can use the DirectoryExists method to determine whether or not a specified directory exists.

The call to DirectoryExists requires FileIOPermission.

This method throws no exceptions.

NoteNote

Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.

To determine if a directory exists

  • Use the My.Computer.FileSystem.DirectoryExists method, supplying the path, to determine whether or not the specified directory exists. The following example checks to determine whether or not the directory C:\backup\logs exists and checks its properties.

    
    Dim logDirectoryProperties As System.IO.DirectoryInfo
    If My.Computer.FileSystem.DirectoryExists("C:\backup\logs") Then
        logDirectoryProperties = My.Computer.FileSystem.GetDirectoryInfo("C:\backup\logs")
    End If
    
    
    
Show: