In MS-DOS command usage, which command removes a directory only if it is empty (contains no files or subdirectories)?

Difficulty: Easy

Correct Answer: RD

Explanation:


Introduction / Context:
File and directory management in MS-DOS uses simple commands with specific behaviors. Deleting a directory safely requires knowing which command enforces the “empty only” rule, preventing accidental removal of content. This is especially important when scripting batch operations that manipulate directory trees.


Given Data / Assumptions:

  • The directory should be removed only if it is empty.
  • We are operating with standard DOS shell commands.
  • No recursive deletion (like DELTREE) is implied in the question.


Concept / Approach:

The RD (or RMDIR) command removes an empty directory. If files or subfolders exist, RD fails, protecting contents by default. DEL/ERASE act on files, not directories. MD creates a directory rather than removing it. For recursive deletions, DOS provided DELTREE, but that is outside this question's scope and purposely riskier.


Step-by-Step Solution:

Identify the command that targets directories specifically.Confirm behavior: succeeds only if directory is empty.Exclude file deletion (DEL/ERASE) and directory creation (MD).Choose RD.


Verification / Alternative check:

Typing HELP RD or RD /? in DOS explains that RD removes a directory, failing if it contains files. This matches the requirement precisely.


Why Other Options Are Wrong:

  • DEL .: deletes files in current directory, not the directory itself.
  • ERASE: synonym for DEL (files only).
  • MD: makes a directory, opposite of the task.
  • None of the above: incorrect because RD is valid and correct.


Common Pitfalls:

  • Assuming DEL can delete directories; it cannot unless combined with tools like DELTREE.
  • Attempting RD on nonempty directories, which will fail and require cleaning files first.


Final Answer:

RD.

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion