See Also Example
Removes an existing directory.
Syntax
RmDir path
Remarks
The argument path is a string expression 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.
ChDir Statement
CurDir, CurDir$ Functions
MkDir Statement
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."
Else
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