Directory.Exists Method (String)

 

Determines whether the given path refers to an existing directory on disk.

Namespace:   System.IO
Assembly:  mscorlib (in mscorlib.dll)

static member Exists : 
        path:string -> bool

Parameters

path
Type: System.String

The path to test.

Return Value

Type: System.Boolean

true if path refers to an existing directory; false if the directory does not exist or an error occurs when trying to determine if the specified directory exists.

The path parameter is permitted to specify relative or absolute path information. Relative path information is interpreted as relative to the current working directory.

Trailing spaces are removed from the end of the path parameter before checking whether the directory exists.

The path parameter is not case-sensitive.

If you do not have at a minimum read-only permission to the directory, the Exists method will return false.

The Exists method returns false if any error occurs while trying to determine if the specified file exists. This can occur in situations that raise exceptions such as passing a file name with invalid characters or too many characters, a failing or missing disk, or if the caller does not have permission to read the file.

The following example takes an array of file or directory names on the command line, determines what kind of name it is, and processes it appropriately.

No code example is currently available or this language may not be supported.

FileIOPermission

for reading files. Associated enumeration: FileIOPermissionAccess.Read

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Return to top
Show: