System.IO.Directory.CreateDirectory Method

Creates all directories and subdirectories in the specified path unless they already exist.

Syntax

public static DirectoryInfo CreateDirectory (string path)

Parameters

path
The directory to create.

Returns

An object that represents the directory at the specified path. This object is returned regardless of whether a directory at the specified path already exists.

Remarks

Any and all directories specified in path are created, unless they already exist or unless some part of path is invalid. If the directory already exists, this method does not create a new directory, but it returns a System.IO.DirectoryInfo object for the existing directory.

The path parameter specifies a directory path, not a file path.

Trailing spaces are removed from the end of the path parameter before creating the directory.

You can create a directory on a remote computer, on a share that you have write access to. UNC paths are supported; for example, you can specify the following for path: \\2009\Archives\December in Visual Basic, and \\\\2009\\Archives\\December in C#.

Creating a directory with only the colon character (:) is not supported, and will cause a NotSupportedException to be thrown.

Requirements

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