In order to remove subdirectories in Windows from the command line, you used to have to use an additional tool called deltree which would recursively remove all files and directories. With Windows 7+ you have an option in the RMDIR / RD command.

Here is how you use the RMDIR command line function and the new /S option.

RMDIR / RD includes an option to recursively remove directories.

Rmdir (rd)
Removes (that is, deletes) a directory.
Syntax
rmdir [Drive:]Path [/s] [/q]
rd [Drive:]Path [/s] [/q]

Parameters
[Drive:]Path : Specifies the location and name of the directory that you want to delete.
/s : Removes the specified directory and all subdirectories including any files. Use /s to remove a tree.
/q : Runs rmdir in quiet mode. Deletes directories without confirmation.
/? : Displays help at the command prompt.

Examples
To delete a directory named \User\Smith, first ensure that the directory is empty. To do this, type:
Rmdir \user\smith /a
Only the “.” and “..” symbols should display.
Then, from any directory except \User\Smith, type:
rmdir \user\smith
To delete the directory \User and all of the subdirectories and files, type:
rmdir /s \user

To delete the directory \User and all of the subdirectories and files without being prompted to confirm each directory, type:
rmdir /s /q \user

Leave a Reply