My.Computer.FileSystem.DirectoryExists Method

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

Parameters

  • directory
    String. Path of the directory. Required.

Return Value

True if the directory exists; otherwise False.

Exceptions

This method throws no exceptions.

Remarks

The call to DirectoryExists requires FileIOPermission.

Tasks

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

To

See

Determine if a directory exists

How to: Determine if a Directory Exists in Visual Basic

Example

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

Requirements

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

Permissions

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.

See Also

Tasks

How to: Determine if a File Exists in Visual Basic

Walkthrough: Manipulating Files and Directories in Visual Basic

Reference

My.Computer.FileSystem Object

DirectoryExists

Other Resources

Creating, Deleting, and Moving Files and Directories in Visual Basic