RmDir Statement

See Also2ND0JZ              Example8HUF0IG>Low

Removes an existing directory.


RmDir path


The argument path is a string expression1330R89 that specifies the name of the directory to be removed.  This argument must have 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 RmDir statement works like the operating system command RMDIR, except that it cannot be abbreviated to RD like the system command.  If the directory to be removed contains anything except the working directory ( '.' ) and the parent directory ( '..' ), an error occurs.

See Also

ChDir StatementPMFGU6

CurDir, CurDir$ Functions3DE0TX

MkDir StatementPWIGU6

RmDir Statement Example

The example uses the RmDir statement to remove a previously created directory at the user's request.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.


Sub Form_Click ()

   Const MB_YESNO = 4                    ' Yes and No buttons

   Const IDNO = 7                        ' No response

   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, MB_YESNO)          ' Display message box and get

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

End Sub