CMD Simulator
File Managementrd

RD Command – Remove Directories in Windows Command Prompt

Master the RD command to delete empty directories in Windows CMD. RD is identical to RMDIR. Complete guide with syntax, /S /Q parameters, examples, and tips for safe folder deletion.

Rojan Acharya·
Share

The RD command (Remove Directory) is a Windows Command Prompt utility that deletes empty directories from the file system, or removes directories and all their contents recursively with the /S parameter. RD is the shorthand for RMDIR—both work identically. Use RD to remove single empty folders, delete directories with all files and subdirectories using /S, or combine with /Q for silent deletion without prompts; the full name RMDIR provides the same functionality for those who prefer explicit command names.

Whether you're a system administrator cleaning up old project directories, a developer removing build output folders, or a power user managing disk space by deleting unused folders, RD provides reliable directory deletion with recursive options and confirmation control. IT professionals rely on RD for automated cleanup tasks, directory structure maintenance, and disk space management across enterprise environments.

This comprehensive guide covers RD syntax, all parameters and options, practical examples for safe directory deletion, troubleshooting tips for deletion failures, related directory management commands, and frequently asked questions. By the end, you'll confidently remove directories from the command line for file system cleanup, project management, and disk space optimization tasks.

What Is the RD Command?

The RD command is a file system management tool in Windows Command Prompt that removes directories from the file system. By default, RD only deletes empty directories; attempting to remove a directory containing files or subdirectories produces an error. Use the /S parameter to delete directories recursively with all contents, including files and subdirectories.

RD works in Command Prompt (CMD), Windows PowerShell (with CMD compatibility), Windows Terminal, and is available in all Windows versions from MS-DOS through Windows 11, Windows Server 2022, and all enterprise editions. The command has a full-name variant RMDIR that functions identically, offering a more descriptive alternative for scripts and documentation.

The command's power and permanence make it essential for directory cleanup and file system maintenance—but also require careful use to prevent accidental data loss. Always verify directory contents before deletion, especially when using /S for recursive deletion.

RD vs RMDIR

  • RD: Shorter; preferred for interactive use; saves typing
  • RMDIR: Full name; preferred for scripts and documentation; self-documenting

Both commands are identical. Use RD for speed in interactive sessions, RMDIR for clarity in scripts.

Syntax

RD [/S] [/Q] [drive:]path
RMDIR [/S] [/Q] [drive:]path

Parameters

ParameterDescription
/SRemoves the directory and all contents (files and subdirectories) recursively
/QQuiet mode; does not prompt for confirmation when used with /S
[drive:]pathSpecifies the directory to remove (required)

Default behavior: Without /S, RD only deletes empty directories. With /S, RD deletes the directory and everything inside it. With /S /Q, deletion is silent—no confirmation prompt.

How to Use RD Command

Remove Empty Directory

Delete a directory that contains no files or subdirectories:

RD emptyfolder
RD C:\Temp\OldFolder

The directory is deleted immediately if it's empty. If it contains files or subdirectories, RD displays an error.

Remove Directory with Full Path

Specify the complete path to delete a directory anywhere on your system:

RD C:\Temp\OldFolder
RD D:\Projects\Archive

Use absolute paths for clarity and reliability in scripts.

Remove Directory and All Contents (/S)

Use /S to delete a directory recursively, including all files and subdirectories:

RD /S C:\Temp\ProjectBackup
RD /S D:\OldProjects

Windows prompts "Are you sure (Y/N)?" before deleting. Type Y to confirm.

Remove Without Confirmation (/S /Q)

Combine /S and /Q to delete directories and contents without prompting for confirmation:

RD /S /Q C:\Temp\Cache
RD /S /Q D:\Build\Output

Use with caution—deletion is immediate and permanent without confirmation.

Remove Multiple Directories

Delete several directories by chaining commands with &&:

RD folder1 && RD folder2 && RD folder3
RD /S /Q dir1 && RD /S /Q dir2

Each directory is deleted in sequence.

Remove Directory on Different Drive

Specify the drive letter to delete directories on other drives:

RD D:\OldData
RD /S /Q E:\Backup\2025

RD works across all local drives and mapped network drives.

Remove Directory with Spaces in Name

Enclose paths containing spaces in double quotes:

RD "My Old Folder"
RD /S /Q "C:\Program Files\Old App"

Without quotes, Windows interprets each word as a separate argument.

Remove Nested Directory Structure

Use /S to delete entire directory trees:

RD /S /Q C:\Projects\OldApp

This removes OldApp and all subdirectories, files, and nested folders within it.

Remove Current Directory's Subdirectory

Delete a subdirectory of your current location:

RD subfolder
RD /S /Q build\output

Use relative paths for convenience when working in a specific directory.

Common Use Cases

  1. Delete empty directories – Use RD to clean up unused empty folders left behind by applications or file operations.

  2. Remove temporary folders – Use RD /S /Q to delete temp directories and their contents for disk cleanup and system maintenance.

  3. Clean up project directories – Use RD /S to remove old project folders with all files, freeing disk space and organizing file systems.

  4. Delete build output folders – Use RD /S /Q build or RD /S /Q dist to remove compilation outputs before fresh builds.

  5. Remove cache directories – Use RD /S to clear application cache folders for troubleshooting or disk space recovery.

  6. Clean up after installations – Use RD to remove leftover installer directories and temporary extraction folders.

  7. Batch directory cleanup – Use RD in scripts to automate folder deletion tasks in maintenance workflows or scheduled cleanup operations.

  8. Remove node_modules – Use RD /S /Q node_modules to delete large dependency folders in JavaScript projects.

  9. Delete user profile remnants – Use RD to remove old user profile directories after account deletion or system cleanup.

  10. Clean up test directories – Use RD /S /Q to remove test data directories after testing or development work.

  11. Remove backup directories – Use RD to delete old backup folders after verifying newer backups exist.

  12. Prepare for fresh installations – Use RD /S /Q to remove old application directories before reinstalling software.

Tips and Best Practices

  1. Always verify the path before using /S – Use DIR to confirm directory contents before running RD /S to avoid accidental data loss: DIR /S foldername then RD /S foldername.

  2. Use /Q carefully – The /Q parameter bypasses confirmation prompts and deletes immediately. Only use when you're certain about deletion.

  3. RD cannot delete the current directory – Use CD .. to move up first: CD .. then RD oldfolder. You cannot delete the directory you're currently in.

  4. Quote paths with spaces – Enclose paths containing spaces in double quotes: RD "My Old Folder". Without quotes, Windows treats each word as a separate directory name.

  5. Use DIR to verify emptiness – Before running RD without /S, use DIR foldername to verify the directory is empty.

  6. Combine with IF EXIST in scripts – Check directory existence before deletion: IF EXIST folder RD /S /Q folder. This prevents errors when directories don't exist.

  7. RD cannot delete read-only, system, or hidden files – Use ATTRIB -R -S -H /S /D foldername\*.* first to clear attributes, then use RD /S.

  8. Test with non-critical directories first – Practice RD commands with test directories before running them on important data.

  9. Use RD for interactive work – The shorter RD saves typing in interactive sessions. Use RMDIR in scripts for clarity.

  10. Verify deletion succeeded – After RD, use DIR parent_directory to confirm the directory was deleted.

  11. Use ROBOCOPY for complex deletions – For directories with special permissions or very long paths, use ROBOCOPY empty_folder target_folder /MIR then RD target_folder.

  12. Document deletion operations – In scripts, add comments explaining why directories are being deleted to aid future troubleshooting.

Troubleshooting Common Issues

"The directory is not empty" Error

Problem: RD displays "The directory is not empty" when trying to delete a directory.

Cause: The directory contains files or subdirectories, and you're using RD without /S.

Solution: Use /S to delete the directory and all contents:

RD /S foldername

Or manually delete contents first:

DEL foldername\*.*
RD foldername

Prevention: Use /S when deleting directories with contents. Use DIR foldername to check contents before deletion.

"Access is denied" Error

Problem: RD fails with "Access is denied" when trying to delete directories.

Cause: Insufficient permissions, directory is in use by a running program, or files within have read-only or system attributes.

Solution:

  • Close programs using the directory (check Task Manager)
  • Run Command Prompt as Administrator for system directories
  • Clear file attributes: ATTRIB -R -S -H /S /D foldername\*.* then RD /S foldername
  • Verify you have delete permissions: ICACLS foldername

Prevention: Run CMD as Administrator when deleting system directories. Close programs before deleting their directories.

"The system cannot find the path specified" Error

Problem: RD reports it cannot find the specified directory.

Cause: Directory doesn't exist, incorrect path, typo, or directory is hidden.

Solution:

  • Verify the directory exists with DIR parent_directory
  • Use DIR /A:H to list hidden directories
  • Check for typos in the path
  • Use Tab completion to avoid path errors

Prevention: Use DIR to verify directories exist before attempting deletion. Copy paths from Explorer for accuracy.

Cannot Delete Current Directory

Problem: RD fails when trying to delete the directory you're currently in.

Cause: RD cannot remove the current working directory. You must be in a parent or sibling directory.

Solution: Change to parent first:

CD ..
RD oldfolder

Or use absolute path from different directory:

CD C:\
RD /S /Q C:\Users\Me\oldfolder

Prevention: Always CD .. out of a directory before deleting it with RD.

Related Commands

DEL / ERASE – Delete Files

DEL (or ERASE) deletes files only, not directories. Use when you need to remove files before RD, or when cleaning directory contents.

Key difference from RD:

  • DEL deletes files
  • RD deletes directories (and optionally their contents with /S)

Example:

DEL folder\*.*
RD folder

When to use: Two-step deletion, removing files before directory removal.

MKDIR / MD – Create Directories

MKDIR (or MD) creates new directories. Use when you need to recreate directory structures after RD cleanup.

When to use: Rebuilding directory structures, creating replacement folders.

CD / CHDIR – Change Directory

CD (or CHDIR) changes the current working directory. Use before RD when you need to exit the directory you want to delete: CD .. then RD folder.

When to use: Navigating out of directories before deletion.

ATTRIB – Modify File Attributes

ATTRIB changes file attributes. Use before RD /S when directories contain read-only, system, or hidden files that prevent deletion.

Example:

ATTRIB -R -S -H /S /D foldername\*.*
RD /S /Q foldername

When to use: Preparing protected files for deletion.

Frequently Asked Questions

What is the difference between RD and RMDIR?

There is no difference; RD and RMDIR are identical commands. RD is the shorthand (Remove Directory), and RMDIR is the full name. Both accept the same syntax and parameters and produce identical results. Most users prefer RD for brevity in interactive sessions.

What does RD /S do?

RD /S removes the directory and all its contents recursively—files, subdirectories, and nested folders. Without /S, RD only deletes empty directories. Windows prompts for confirmation before recursive deletion unless you also use /Q.

What does RD /Q do?

RD /Q enables quiet mode, suppressing the "Are you sure (Y/N)?" confirmation prompt when used with /S. Use RD /S /Q for silent recursive deletion. Use with caution—deletion is immediate and irreversible.

How do I delete a directory with files in it?

Use RD /S foldername to delete the directory and all contents. Use RD /S /Q foldername to skip the confirmation prompt. Always verify the path first with DIR foldername to avoid accidental data loss.

Can RD delete the current directory?

No. RD cannot delete the directory you're currently in. Use CD .. to move to the parent directory first, then run RD foldername. Or use an absolute path: RD /S /Q C:\path\to\folder from a different directory.

How do I delete a directory with spaces in the name?

Enclose the path in double quotes: RD "My Old Folder" or RD /S /Q "C:\Program Files\Old App". Without quotes, Windows treats each word as a separate argument.

Why does RD fail with "Access is denied"?

This occurs when you lack delete permissions, the directory is in use by a program, or files within have read-only, system, or hidden attributes. Solutions: Close programs, run as Administrator, or use ATTRIB -R -S -H /S /D folder\*.* before RD /S.

Can RD recover deleted directories?

No. RD permanently deletes directories without sending them to the Recycle Bin. Recovery requires third-party file recovery software and is not guaranteed. Always verify before deletion and maintain backups of critical data.

How do I delete node_modules?

Use RD /S /Q node_modules to delete the node_modules folder and all dependencies. This can take a moment for large projects. Run from the project root directory.

What does "The directory is not empty" mean?

RD without /S only deletes empty directories. If the directory contains files or subdirectories, RD displays this error. Use RD /S to delete the directory and all contents recursively.

Can RD delete directories on network drives?

Yes. RD works with mapped network drives: RD Z:\OldFolder or RD /S /Q Z:\Projects. For UNC paths: RD \\server\share\folder. Ensure you have delete permissions on the network share.

How do I delete read-only files in a directory?

RD /S may fail on directories containing read-only files. First clear attributes: ATTRIB -R -S -H /S /D foldername\*.* then RD /S /Q foldername. Run as Administrator for system files.

Quick Reference Card

CommandPurposeExample Use Case
RD folderDelete empty directoryRemove empty folder
RD /S folderDelete with contentsRemove folder tree
RD /S /Q folderSilent recursive deleteScript cleanup
RD "My Folder"Delete with spacesQuote path
CD .. then RD folderExit then deleteCurrent directory
DIR folder then RD /S folderVerify then deleteSafe deletion
IF EXIST x RD /S /Q xDelete if existsScript safety

Try RD Command Now

Ready to practice removing directories safely? Use our Windows Command Simulator to run RD commands in your browser without risk. No installation required—practice RD, RD /S, RD /S /Q, and path handling in a safe environment.

Explore the full Commands Reference for more Windows CMD utilities, including RMDIR (identical to RD), directory operations (MKDIR, CD), and file management commands.

Summary

The RD command is the essential Windows tool for removing directories from the command line. Use RD to delete empty folders, or RD /S to remove directories and all contents recursively. Combine with /Q for silent deletion in scripts. RD and RMDIR are identical—use RD for brevity, RMDIR for clarity in scripts.

Remember that RD bypasses the Recycle Bin—deletion is permanent and irreversible. Always verify paths with DIR before deletion, especially when using /S. RD cannot delete the current directory; use CD .. first.

Master RD for system administration tasks like build cleanup, cache removal, project directory deletion, and automated disk space management. Understanding RD's /S and /Q parameters ensures efficient and safe directory removal in Windows environments.