Software-OK
≡... News | ... Home | ... FAQ | Impressum | Contact | Listed at | Thank you |

  
HOME ► Faq ► FAQ - Command Prompt - Windows 11, 10, etc. ► ««« »»»

Command line to delete empty folders Windows 11, 10, ....!


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!
2.) ... More solutions to delete empty folders under Windows!



3.) ... Important Questions and Answers: Delete empty folders under Windows and Co.!




1. Hold down the Shift key, right-click a folder

2. Click here Open Command Prompt (or PowerShell, or Terminal APP)
(the Command Prompt is open on the current folder)


3. When you are in the Command Prompt in the desired Directory, run the following command line:


for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d"



Note:
You need to make sure that you are running the following command from the exact path of the parent folder where you need to find and remove empty subfolders.

or this: ► Script to delete!

The Command for Address-Bar in ► Quad-Explore for Windows 11, 10, ... or ► Windows 11, 10, ... File Explorer


cmd /k "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d""




(Image-1) Example command line to delete empty folders on Windows 11, 10, ....!
Example command line to delete empty folders on Windows 11, 10, ....!

-
▲ Back to the top ▲


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.



3.) Important questions and answers: Delete empty folders under Windows and Co.!




1. How do I delete empty folders in Windows 11?
You can delete empty folders in Windows 11 by using Command Prompt, PowerShell, or File Explorer.

2. What command line tools can I use to delete empty folders?
You can use Command Prompt, PowerShell, or Windows Terminal.

3. What is the command in Command Prompt to delete empty folders?
The command is: "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d""

4. How do I open Command Prompt in Windows 10?
Press Win + X and select "Command Prompt" or "Windows Terminal" from the menu.

5. Can I delete empty folders using PowerShell?
Yes, you can delete empty folders using PowerShell.


6. How do I navigate to a specific directory in Command Prompt?
Use the command "cd" followed by the path of the directory, e.g. "cd C:\My-Folder".

7. What commands do I use in PowerShell to find empty folders?
Use the command: "Get-ChildItem -Directory -Recurse | Where-Object { $_. GetFiles(). Count -eq 0 -and $_. GetDirectories(). Count -eq 0 }"

8. How do I open File Explorer with a keyboard shortcut?
Press Win + E

9. How do I delete empty folders in File Explorer?
Navigate to the folder, type "kind:folder size:empty" in the search bar, select the empty folders, and delete them.

10. What does the command "dir /s /b /ad" mean in the command prompt?
This command lists all directories and subdirectories in the current directory.



11. What method can I use to delete empty folders in Quad Explorer?
Use the command "cmd /k "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d""" in the address bar.

12. Can I undo the deletion process for empty folders in File Explorer?
Yes, you can undo the deletion as long as the Recycle Bin has not been emptied.

13. How do I enter a search query for empty folders in File Explorer?
Type "kind:folder size:empty" in the search bar at the top right of File Explorer.

14. How can I make sure that I only delete empty folders?
Check the search results or lists in Command Prompt or PowerShell before running the delete commands.

15. What are the options for deleting empty folders in Windows 10?
You can use Command Prompt, PowerShell, Windows Terminal, or File Explorer.



16. How does the "rd" command work in Command Prompt?
The command "rd" (remove directory) deletes a specified directory if it is empty.

17. Can I save the command to delete empty folders in PowerShell script form?
Yes, you can save the command to a ".ps1" file and run it.

18. What do I do if I accidentally delete a folder?
Restore it from the Trash if it hasn't been emptied yet.

19. Which versions of Windows support the "for /f" command?
The command is supported by all modern versions of Windows, including Windows 10 and 11.20

. How do I use the "Remove-Item" command in PowerShell?
Use "Remove-Item" followed by the path of the item to be deleted, e.g. "Remove-Item -Path "C:\Path\to\Folder" -Force".



21. Can I delete empty folders with a single command in Command Prompt?
Yes, use the command "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d"".

22. How do I navigate to a specific directory in File Explorer?
Enter the path of the directory in the address bar at the top and press Enter.

23. What do I do if Command Prompt doesn't find empty folders?
Make sure that you are in the correct directory and that there are actually empty folders.

24. What are the advantages of using PowerShell over Command Prompt?
PowerShell offers more functionality and scripting capabilities, as well as more powerful syntax.

25. Can I use the address bar in File Explorer to delete empty folders?
Yes, type "cmd /k "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d""" in the address bar.



26. What are the steps to find empty folders in File Explorer?
Open File Explorer, navigate to the desired directory, and type "kind:folder size:empty" in the search bar.

27. How can I open the Command Prompt from a folder's context menu?
Hold down the Shift key, right-click on the folder, and select "Open Command Prompt Here."

28. Can I modify the Get-ChildItem command in PowerShell?
Yes, you can customize "Get-ChildItem" with various parameters and filters to find specific files and folders.

29. How to Delete Empty Folders in recursive to a specific directory?
In the command prompt, run the command "for /f "delims=" %d in ('dir /s /b /ad ^| sort /r') do rd "%d"".

30. What warnings should I pay attention to when deleting empty folders?
Carefully check that the folders are really empty and that you are not deleting any data you need, as the deletion process cannot be undone.



31. How do I open PowerShell with a keyboard shortcut?
Press Win + X and select "Windows PowerShell" or "Windows Terminal" from the menu.

32. Can I automate the deletion process in the command prompt?
Yes, you can create a script that contains the delete command and have that script run automatically.

33. How does the search function in File Explorer work to find empty folders?
Type "kind:folder size:empty" in the search bar at the top right of File Explorer to search for empty folders.




FAQ 98: Updated on: 31 May 2024 06:22 Windows
Windows-Console

Delete partition with Diskpart under Windows 11, 10, ... and MS Server!


It is easy to delete a partition with Diskpart on all Windows 11, 10, Desktop and MS Server 2022, 2019, operating systems Contents: 1. Deleting
Windows-Console

Set maximum password age / expiration date via Windows PowerShell!


Set the maximum password age or the expiration date via Windows PowerShell under MS Windows 11, 10, Desktop and MS Server If your computer is running
Windows-Console

Change Windows 11, 10, ... time zone via Terminal, Powershell, command prompt!


Its easy to change Windows 11, 10, or MS Server time zone via Terminal, PowerShell, command prompt Changing the Windows time zone is sometimes faster
Windows-Console

Difference Between PowerShell and Command Prompt?


The range of commands and the possibilities are the main difference between PowerShell and the command prompt on Windows 11, 10, and MS Server OS Contents:
Windows-Console

Connection to remote desktop service via command prompt!


It is easy to start a connection to the Remote Desktop Service via the command prompt with arguments on Windows 11, 10, and MS Server OS   Contents:
Windows-Console

Command line arguments in the command prompt with examples!


For parameters that can be passed when the batch file is called and other variables via the set on Windows 11, 10, and MS Server OS Contents: 1.
Windows-Console

Waiting for keyboard input Command prompt Script?


Often you want to stop the script in the batch file and wait for the user to press Enter, or variables to process on Windows 11, 10, and MS Server OS

»»

  My question is not there in the FAQ
Asked questions on this answer:
Keywords: windows, 11, 10, console, command, line, delete, empty, folders, here, microsoft, desktop, server, Questions, Answers, Software




  

  + Freeware
  + Order on the PC
  + File management
  + Automation
  + Office Tools
  + PC testing tools
  + Decoration and fun
  + Desktop-Clocks
  + Security

  + SoftwareOK Pages
  + Micro Staff
  + Freeware-1
  + Freeware-2
  + Freeware-3
  + FAQ
  + Downloads

  + Top
  + Desktop-OK
  + The Quad Explorer
  + Don't Sleep
  + Win-Scan-2-PDF
  + Quick-Text-Past
  + Print Folder Tree
  + Find Same Images
  + Experience-Index-OK
  + Font-View-OK


  + Freeware
  + 12-Ants
  + Q-Dir
  + PaintOkay
  + DirPrintOK
  + FontViewOK
  + MeinPlatz
  + DesktopOK
  + IsMyMemoryOK
  + StressTheGPU
  + PAD-s


Home | Thanks | Contact | Link me | FAQ | Settings | Windows 10 | gc24b | English-AV | Impressum | Translate | PayPal | PAD-s

 © 2025 by Nenad Hrg softwareok.de • softwareok.com • softwareok.com • softwareok.eu


► Have Word documents read aloud in Microsoft Word? ◄
► Safe from spying with Offline PC, MacOS, Windows, Linux? ◄
► Defender slows down the development of applications, programs and APPs! ◄
► Quickly disable windows user account via command line? ◄


This website does not store personal data. However, third-party providers are used to display ads,
which are managed by Google and comply with the IAB Transparency and Consent Framework (IAB-TCF).
The CMP ID is 300 and can be individually customized at the bottom of the page.
more Infos & Privacy Policy

....