Delete Empty Folders in Seconds Using CMD

Clean up your file system by removing hundreds of empty folders instantly. A simple one-line command does the trick—no software needed.

Delete Empty Folders in Seconds Using CMD
On this page
  1. Introduction
  2. Simple Method (Current Folder Only)
  3. Recursive Method (All Subfolders)
  4. Safety Tips
  5. FAQ

Introduction

TL;DR

Run in CMD: for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d" 2>nul

After deleting files or uninstalling programs, you're left with empty folder skeletons cluttering your drives.

Manually finding and deleting them is tedious. Let CMD do the work in seconds.

Simple Method (Current Folder Only)

This command removes empty folders in your current directory (not subfolders).

1Navigate to Target Folder

Open CMD in the folder you want to clean. Click the address bar, type cmd, and press Enter.

2Run the Command

Command Prompt
C:\OldProjects>for /d %d in (*) do @rd "%d" 2>nul
(Attempts to delete all directories; only empty ones get removed)
How It Works

The rd command fails on non-empty folders. 2>nul hides those error messages.

Recursive Method (All Subfolders)

This powerful command finds and removes ALL empty folders in the entire folder tree.

Recursive Empty Folder Deletion Logic
Command Prompt
for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d" 2>nul
Processing...
(silently removes empty folders from deepest to shallowest)

PowerShell Alternative

PowerShell is cleaner and easier to read:

PowerShell
Get-ChildItem -Directory -Recurse | Where-Object { (Get-ChildItem $_.FullName -Force).Count -eq 0 } | Remove-Item -WhatIf
(Remove -WhatIf to actually delete. It's a preview flag.)

Safety Tips

Test First

Run on a test folder before your important directories. Create some empty folders and verify they're removed correctly.

Avoid System Folders

Don't run this on C:\Windows or C:\Program Files. Some programs expect empty folders to exist.

No Recycle Bin

Folders removed by rd bypass the Recycle Bin. They're gone permanently.

Frequently asked questions

Why use sort /r in the command?

It sorts folders in reverse alphabetical order, which typically means deeper paths first. You must delete child empty folders before parents, or the parent won't appear empty yet.

Can I undo this?

No. Once deleted with rd, folders are gone. If the folder contained hidden files (like .DS_Store on Mac or desktop.ini on Windows), those are deleted too.

Why do some empty folders not get deleted?

They may contain hidden or system files. Add -Force to PowerShell commands to see hidden items.

Keep reading

Create a Folder Structure Template with One CommandProductivity

Create a Folder Structure Template with One Command

Set up project directories instantly. Learn to create entire folder hierarchies with a single CMD command—perfect for developers and organized workflows.

MD Kawsar· January 18, 2026 · 4 min read
Find Large Files Eating Your Disk Space with CMDProductivity

Find Large Files Eating Your Disk Space with CMD

Discover which files are hogging your storage. Learn CMD and PowerShell commands to quickly find the biggest files on your computer without third-party tools.

MD Kawsar· January 18, 2026 · 4 min read
Batch Rename Files with CMD: The Complete GuideProductivity

Batch Rename Files with CMD: The Complete Guide

Rename hundreds of files in seconds using Windows Command Prompt. Learn wildcards, patterns, and batch processing without installing any software.

MD Kawsar· January 18, 2026 · 5 min read

Want us to build this for you?

Tell us what data or workflow you need. We reply within a few hours.

Book a free call ↗