Mono Class Library: System.IO.Directory Overview | Members

System.IO.Directory.Exists Method

Returns a bool indicating whether the specified directory exists.

public static bool Exists (string path)

Parameters

path
A string containing the name of the directory to check.

Returns

true if the caller has the required permissions and path contains the name of an existing directory; otherwise, false. If path is null, a zero-length string, or contains the name of a file, returns false.

Permissions

TypeReason
System.Security.Permissions.FileIOPermissionRequires permission to read the specified directory. See System.Security.Permissions.FileIOPermissionAccess.Read.

Exceptions

TypeReason
ArgumentExceptionpath is a zero-length string, contains only white space, or contains one or more implementation-defined invalid characters.
System.IO.PathTooLongExceptionThe length of path or the absolute path information for path exceeds the system-defined maximum length.
System.IO.DirectoryNotFoundExceptionpath was not found.

Remarks

If the caller does not have sufficient permissions to read the files in the directory specified by path, no exception is thrown and the method returns false regardless of the existence of path.

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

Note: To obtain the current working directory, see Directory.GetCurrentDirectory.

Requirements

Namespace: System.IO
Assembly: mscorlib (in mscorlib.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0