If you want to delete empty folders via command line, here is the command for all Microsoft's Windows 11, 10, ... Desktop and MS Server OS!Contents: 1.) ...Delete empty folders Windows!
|
(Image-1) Example command line to delete empty folders on Windows 11, 10, ....! |
![]() |

2.) More solutions to delete empty folders under Windows!
To delete empty folders in Windows, you can use the built-in file explorer (Windows Explorer) or command line tools such as Command Prompt or PowerShell. Here's how to do this using both methods:
Using File Explorer:
Open File Explorer by pressing Win + E or clicking the File Explorer icon on the taskbar.
Navigate to the folder where you want to delete empty folders.
In the search bar in the upper right corner of File Explorer, type Enter and press Enter. This will search for all empty folders in the current directory and its subdirectories.
kind:folder size:empty
Select all empty folders you want to delete. You can press Ctrl + A to select all, or hold Ctrl and click individual folders.
Once the empty folders are selected, right-click one of them and select "Delete" from the context menu.
Windows will ask you to confirm the deletion. Click "Yes" to delete the selected empty folders.
Using the Command Prompt:
Open the Command Prompt. You can do this by pressing Win + X and selecting "Command Prompt" or "Windows Terminal" from the menu.
Use the command to navigate to the directory where you want to start searching for empty folders. To e.g. For example, to navigate to the C:\My Folder directory, you can use the following command: cd
cd C:\My folder
To list all empty directories in the current directory and its subdirectories, you can use the following command:
for /f "delims=" %d in ('dir /ad /s /b ^| sort /r') do rd "%d"
This command recursively searches for empty directories and deletes them.
Windows will ask you to confirm before deleting each folder. Enter "Y" for Yes to confirm the deletion.
Using PowerShell:
Open PowerShell. You can do this by pressing Win + X and selecting "Windows PowerShell" or "Windows Terminal" from the menu.
Use the command to navigate to the directory where you want to start searching for empty folders, similar to the command prompt method.cd
To list and delete empty directories in the current directory and its subdirectories, you can use the following PowerShell -Use command:
Get-ChildItem -Directory -Recurse | Where-Object { $_.GetFiles().Count -eq 0 -and $_.GetDirectories().Count -eq 0 } | Remove-Item -Force
PowerShell deletes the empty folders without prompting for confirmation.
Info:
Remember to be careful when deleting folders, especially when using the command line methods, as there is no "undo" option. Make sure you have selected the correct folders before confirming the deletion.
Remember to be careful when deleting folders, especially when using the command line methods, as there is no "undo" option. Make sure you have selected the correct folders before confirming the deletion.
FAQ 98: Updated on: 7 October 2023 15:49