This documentation is archived and is not being maintained.

MkDir Function

Visual Studio 2008

Creates a new directory.

The My feature gives you greater productivity and performance in file I/O operations than MkDir. For more information, see My.Computer.FileSystem.CreateDirectory Method.

Public Sub MkDir(ByVal Path As String)


Required. String expression that identifies the directory to be created. The Path may include the drive. If no drive is specified, MkDir creates the new directory on the current drive.

Exception type

Error number




Path is not specified or is empty.



Permission denied.



Directory already exists.

See the "Error number" column if you are upgrading Visual Basic 6.0 applications that use unstructured error handling. (You can compare the error number against the Number Property (Err Object).) However, when possible, you should consider replacing such error control with Structured Exception Handling Overview for Visual Basic.

Security noteSecurity Note:

Both read and write file I/O permissions are necessary to create a directory or folder. For more information, see FileIOPermission and Code Access Permissions.

This function creates any new directories specified in Path, unless they already exist or if some part of Path is invalid. The Path parameter must specify a directory path, not a file path.

This example uses the MkDir function to create a directory. If the drive is not specified, the new directory is created on the current drive.

' Make new directory.

This function is not supported.

Namespace: Microsoft.VisualBasic

Module: FileSystem

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