Q(uick)BASIC Statement: RMDIR

Quick View

RMDIR

A statement that interfaces with DOS to remove an existing directory

Worth knowing

Useful and cross-version information about the programming environments of QBasic and QuickBasic.

Syntax
  • CHDIR pathname$
  • MKDIR pathname$
  • RMDIR pathname$
  • FILES [filespec$]
Description/Parameter(s)

CHDIR changes a drive's default directory. MKDIR creates a subdirectory. RMDIR removes a subdirectory. FILES displays the contents of the current directory or a specified directory.

pathname$ The path of the new default directory, subdirectory to create, or subdirectory to remove.
filespec$ A filename or path (may include a drive and DOS wildcard characters). If you don't specify a filespec$, FILES displays all files in the current directory.
Example
MKDIR "C:\TEMP\TEST" CHDIR "C:\TEMP" FILES RMDIR "TEST"
Syntax
  • RMDIR pathspec
Description/Parameter(s)

The pathspec is the name of the directory which is to be deleted. The pathspec must be a string of less than 128 characters.

The directory to be removed must be empty except for the working directory ('.') and the parent directory ('..'); otherwise, one of two error messages is printed, either "Path not found" or "Path/File access error."

RMDIR works like the DOS command of the same name. However, the syntax in BASIC cannot be shortened to RD, as in DOS.

Example

This example shows how to use RMDIR to remove a subdirectory.
Note: Do not run this example unless you have a TEMP subdirectory in a directory SALES, and you want to remove that subdirectory.

CHDIR "C:\SALES\TEMP" 'Move to \TEMP subdirectory in \SALES. KILL "*.*" 'Remove all files in \TEMP. CHDIR ".." 'Move back up to \SALES. RMDIR "TEMP" 'Remove \TEMP subdirectory.
Syntax
  • RMDIR pathname$
Description/Parameter(s)
  • The argument pathname$ is the name of the directory that is to be deleted. It must be a string expression of fewer than 64 characters.

Usage Notes

  • The directory to be removed must be empty except for the working directory ('.') and the parent directory ('..'); otherwise, BASIC generates one of two error messages, either "Path not found" or "Path/File access error."
  • RMDIR works like the DOS command of the same name. However, the syntax in BASIC cannot be shortened to RD, as it can in DOS.
Example

This example uses the RMDIR statement to remove a subdirectory.

CHDIR "C:\SALES\TEMP" 'Move to \TEMP subdirectory in \SALES. KILL "*.*" 'Remove all files in \TEMP. CHDIR ".." 'Move back up to \SALES. RMDIR "TEMP" 'Remove \TEMP subdirectory.