MkDir Statement

See AlsoDPMTH2              Example8CSF0IG>Low

Creates a new directory.


MkDir pathname


The argument pathname is a string expression1330R89 that specifies the name of the directory to be created.  This argument must contain fewer than 128 characters and has the following syntax:

          [drive:] [ \ ]directory[\directory] . . .

The argument drive is an optional drive specification; the argument directory is a directory name.

The MkDir statement works like the operating system command MKDIR, except that it cannot be abbreviated to MD like the system command.

If you use MkDir to create a directory whose name contains an embedded space, you may be able  to access it with some applications, but you can't remove it using standard operating system commands.  To remove such a directory, use the RmDir statement from within Visual Basic or a Visual Basic application.

See Also

ChDir StatementPMFGU6

CurDir, CurDir$ Functions3DE0TX

RmDir StatementQ1KGU6

MkDir Statement Example

The example uses the MkDir statement  to create a \TMP subdirectory off the root directory of the currently logged drive.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Dim Ansr, CurDrv, Msg, TmpPath        ' Declare variables.

   On Error Resume Next                  ' Set up error handler.

   CurDrv = Left(CurDir, 2)              ' Get current drive letter.

   TmpPath = UCase(CurDrv + "\tmp")      ' Make path specification.

   MkDir TmpPath                         ' Make new directory.

   If Err = 75 Then                      ' Check if directory exists.

      Msg = TmpPath & " directory already exists."


      Msg = TmpPath & " directory created."

   End If

   Msg = Msg & " Do you want it removed?"

   Ansr = MsgBox(Msg, 4)                 ' Display message and get

   If Ansr <> 7 Then RmDir TmpPath       ' user response.

End Sub