This documentation is archived and is not being maintained.

My.Computer.FileSystem.DirectoryExists Method

Visual Studio 2008

Returns a Boolean indicating whether the specified directory exists.

' Usage
Dim value As Boolean = My.Computer.FileSystem.DirectoryExists(directory)
' Declaration
Public Function DirectoryExists( _
   ByVal directory As String _
) As Boolean

directory

String. Path of the directory. Required.

True if the directory exists; otherwise False.

This method throws no exceptions.

The call to DirectoryExists requires FileIOPermission.

The following table lists examples of tasks involving the My.Computer.FileSystem.DirectoryExists method.

This example determines whether the directory C:\backup\logs exists and checks its properties.

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

Namespace: Microsoft.VisualBasic.MyServices

Class: FileSystemProxy (provides access to FileSystem)

Assembly: Visual Basic Runtime Library (in Microsoft.VisualBasic.dll)

Availability by Project Type

Project type

Available

Windows Application

Yes

Class Library

Yes

Console Application

Yes

Windows Control Library

Yes

Web Control Library

Yes

Windows Service

Yes

Web Site

Yes

The following permission may be necessary:

Permission

Description

FileIOPermission

Controls the ability to access files and folders. Associated enumeration: Unrestricted.

For more information, see Code Access Security and Requesting Permissions.

Show: