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

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

Using PowerShell and CMD to delete complete directories, with examples?


You can use PowerShell and / or cmd.exe to delete complete directories in one go with subdirectories on Windows 12, 11, 10, ...!



Deleting of Directories Preface:

Deleting directories sometimes makes more sense at the command line than with the Microsoft File Explorer, or Quad Explorer , because of the File Filter (wildcard /placeholder) feature, it makes perfect sense. This is not only possible under Windows 11 / 10 / 8.1 / 7. This type of deletion is often used by administrators, especially on Windows Server 2019, 2016, .... .

 

Solutions / Examples:
1.) ... Deleting the directories from the command prompt (cmd.exe) 
2.) ... Deleting directories using PowerShell! 
3.) ... What should I consider when deleting the directories by command line!

4.) ... Overview of the RD or RMDIR commands!
5.) ... An example of cmd deleting a full directory without asking!
6.) ... The most important commands for handling files/folders in Powershell!

7.) ... Tip: delete date-related data and files without file extensions!




See also: ► How to create at once several subfolders levels (commando-line)?

1.) Deleting the directories from the command prompt (cmd.exe) 


In the Windows Command Prompt, you can use directories with the RD command , or known as RMDIR, or if you  want to delete the folder C:\Folder1, for example , type the following command:

C:>rmdir C:\Folder1
Do not forget to press Enter. 
 
Here we deleted the directory, if the directory contains no file, or subfolder, it is not a problem.  
 
However, if there are files in the specific folder, you must confirm the deletion and use the "/s" argument / parameter! 
 
Here is a simple example: 

C:\Windows\System32>rmdir c:\Folder1
The directory is not empty.

C:\Windows\System32>rmdir c:\Folder1 /s
Do you want to delete "c:\Folder1" (Y/N)? j

C:\Windows\System32>
You can also do this for folders with spaces in the path. 
 
The same command works, but you must enclose the folder name in quotation marks, as shown in the following example. 

C:\Windows\System32>rmdir "c:\Folder 2" /s
Do you want to delete "c:\Folder 2" (Y/N)? y

C:\Windows\System32>
If executed correctly, no error message will be displayed! 
 
To clear the directory in quiet mode without being prompted for confirmation, you can use the /Q parameter . 

C:\Windows\System32>rmdir "c:\Folder 2" /s /q

2.) Deleting directories using PowerShell!

Even with Powershell you can delete directories and files! The RD RMDIR command can also be used in the powershell console. However, this is not the powershell home-made-directories-delete-command and there is hardly any feedback! 

C:\Windows\System32>rmdir "c:\Test Del Folder 2" /s
That would be the correct Powershell command! 
 
Remove-item "C: \Folder 1" and confirm with [Y]

PS C:\Windows\system32> Remove-Item "C:\Folder 1"

Confirm The item at C:\Folder 1 has children and the Recurse parameter was not specified. If you continue, all children will be removed with the item. Are you sure you want to continue?

[Y] Yes [A] Yes to All [N] No [L] No to All [S] Suspend [?] Help (default is "Y"): y

PS C:\Windows\system32>

Here with wildcard (placeholder) function! 
 
Show if the filter works: 
Remove-Item "C:\1\*" -filter *New* -whatif
 
and delete with wildcard (placeholders) Function: 
Remove-Item "C:\1\*" -filter *New*

Sub Example 1:
C:\PS>remove-item "C:\1\*" -include *.doc -exclude *important*
This command deletes from the "C:\1" directory all microsoft office files with file name extension  ".doc" and a name that does not include "important". 

Sub Example 2:
C:\PS>remove-item -path "C:\1\*" -force 

Sub Example 3:
C:\PS>get-childitem "C:\1\" -include *.csv -recurse | remove-item 
This command deletes all of the TXT files in the "C:\1\" directory and all subdirectories recursively.



PS C:\Windows\system32> Remove-Item "C:\1\*" -Filter *New* -whatif
What if: Performing operation "Remove Directory" on Target  "C:\1\New Folder".
What if: Performing operation "Remove Directory" on Target  "C:\1\New Folder (2)".
What if: Performing operation "Remove Directory" on Target  "C:\1\New Folder (3)".
PS C:\Windows\system32> Remove-Item "C:\1\*" -Filter *New*
PS C:\Windows\system32>



-
▲ Back to the top ▲


3.) What should I consider when deleting the directories by command line!

Unlike the file explorer, actions can not be undone, so you have to be clear about what you are deleting. 

"Undo delete"

  make is not here!  
 
Otherwise, quite handy deleting the directories via command line under Microsoft's Windows. 

►► Remove-Item - PowerShell -  command!

4.) Overview of the RD or RMDIR commands!


ColorConsole  [Version 2.6.1001 ]
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Users\Neno>RD /?
Removes (deletes) a directory.

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

/S
Removes all directories and files in the specified directory
in addition to the directory itself.  Used to remove a directory
tree.

/Q
Quiet mode, do not ask if ok to remove a directory tree with /S

C:\Users\Neno>

You can safely use this on the following operating systems: Windows 11, 10 Pro, Enterprise, Home, Windows 8.1, Windows 8, Windows-Server 2019, 2016, 2012, Windows 7 Basic, Professional, Starter, Ultimate and this all for free!



5.) An example cmd delete full directory without asking!



Often you want to delete entire directories/folders with all contents and subdirectories without having to confirm it again and again!

There is no query like “Are you sure” or anything else? If there is no error, there is no feedback! 

( ...see image-1 )



C:\Windows\System32>rmdir c:\Folder-1 /s /q

C:\Windows\System32>




(Image-1) Delete entire directories with PowerShell and CMD!
Delete entire directories with PowerShell and CMD!

-
▲ Back to the top ▲




6.) The most important commands for handling files/folders in PowerShell!



See also: ►  Create Directory to create a directory under Windows 



The PowerShell commands:


    


Remove-Item  = Remove a folder or file
Get-Item  = Show a folder or file
Set-Item  = Change folder or file properties
New-Item  = Create a new folder or file
Get-ChildItem  = Show subfolders



7.) ... Tip: delete date-related data and files without file extensions!



the argument /d -100
to delete all files that are over 100 days old  

the argument *
for all files and folders 

the filter to only delete files without a file extension
if @isdir==FALSE if @ext==\"\"



forfiles /M * /d -100 /c "cmd /c if @isdir==FALSE if @ext==\"\" del @path" 



(Image-3) Example of the address line in Q-Dir!
Example via the address line in Q-Dir!

-
▲ Back to the top ▲


8.) Why is deleting via Command Prompt so popular?


Deleting files using the command prompt (also called “command prompt” or “cmd”) is popular in some cases because it offers certain advantages that can be useful for certain tasks. Here are some reasons why people use Command Prompt to delete files:



Control and Precision: Command Prompt allows users to delete files and directories with great precision. You can enter precise commands to remove only specific files or folders without accidentally touching other files.

►►  Delete all files except recent ones via command line, script or CMD.EXE?



Batch Processing: Command Prompt is suitable for processing multiple files or folders at the same time. You can create scripts or batch files to automatically delete many files at once.

Speed:
Knowing the exact command allows you to quickly delete files and folders in Command Prompt without having to navigate graphical user interfaces.

Access to system files:
Command Prompt often also grants advanced permissions to access and delete protected or system files. This may be necessary in some cases.

Troubleshooting:
In some cases, deleting files using Command Prompt can be helpful to fix serious problems or malware infections where the graphical user interface may be limited.


Info:

However, it is important to note that using Command Prompt also carries risks. A mistyped command can result in important files being accidentally deleted, and Command Prompt often requires administrative privileges, which can be potentially dangerous if used improperly. Therefore, you should be careful and make sure you know what you are doing when using Command Prompt to delete files.



FAQ 33: Updated on: 3 September 2024 12:10 Windows
Windows-Console

CMD commands to control power settings under Windows, with examples?


There are commands to control the power settings under Windows, it makes sense if you want to change them by batch file on Windows 12, 11, 10, etc. OS Here
Windows-Console

Command line CMD background change color, but how, with example?


Also during the command input you can change the CMD background color by command and the text, here an example The color values ​​can be indicated by two
Windows-Console

Disable and enable SmartScreen via CMD BATCH command?


The solution is simple to disable and enable SmartScreen via CMD BATCH command and command prompt Contents: 1. Deactivating the Smart Screen when browsing
Windows-Console

How can I start the program at a certain time CMD, with examples?


In Windows you can start programs via AT at a certain time without additional software programs  Start the cmd.exe and use the command "AT" in the combination
Windows-Console

Copying files with COPY commands, cmd with examples?


In Windows you can copy via COPY command without file explorer, files and directories without additional software Start the cmd.exe and use the command
Windows-Console

Viewing shares, sessions and open files, cmd example?


The command prompt on Windows 11, 10, etc. allows you to view / query shared folders and current sessions / open files   Content: 1. Example: View
Windows-Console

Using SCHTASK for Programs Autostart in all Windows OS, how to?


Time controlled Autostart of Windows 11, 10, etc. programs In new Windows OS you can use SCHTASK to start programs at a certain time   Content: 1.

»»

  My question is not there in the FAQ
Asked questions on this answer:
  1. I want everything to do with Windows?
  2. Windows cmd delete empty directories?
  3. Prompt command to delete?
  4. I am wondering whether to completely delete folders, whether alternatively delete the respective folder in the CMD a instead of searching for the folder path via the Explorer can the delete folder in the CMD console?
  5. Force delete file from Powershell?
  6. Find command remove file by path or folder path, do I need to enter all file paths to delete them at once, or can I enter and use another delete command?
  7. Delete multiple files with PowerShell, if I want to delete multiple files, do I have to enter another command?
  8. Delete Powershell directories?
  9. Help, can't delete a file or folder, what step by step can I use in PowerShell to delete files and folders?
  10. Command prompt delete directory?
  11. Search example delete a folder or delete files and folders what parameters if a folder is not empty?
  12. Can I delete the folder via the CMD console without any intermediate steps without using the MS Windows Explorer or open the desired folder, then completely delete the folder in cmd?
  13. How to delete multiple files using cmd or PowerShell command to remove more than one folder with Windows without checking files within a folder?
  14. Delete Dos command with subdirectories?
  15. Powershell command delete all data in directory?
  16. How do I delete files and folders using Windows PowerShell so delete all files and folders using Windows PowerShell?
  17. Which commands do I need for editing folders, PowerShell commands also CMDlets?
  18. Can I delete a folder using the PowerShell command?
  19. How do I open PowerShell and delete folders with subfolders using Windows PowerShell?
  20. Delete Windows 11 and 10 folders without asking, delete Windows directories powershell?
  21. I like to work with the CMD console under Windows, can I delete folders directly from there?
  22. Win cmd delete command without confirmation?
  23. Cmd delete directory contents Windows 10?
  24. Windows 11 and 10 cmd not delete empty directory?
  25. Delete folders and files with Windows command prompt?
  26. Delete files in subdirectories windows?
  27. What if I can't delete a file or folder on your computer, want to use PowerShell to force delete a file or remove all items from a folder?
  28. Delete complete folder with subfolder of cmd level?
  29. Can I create and delete many folders in a few minutes using PowerShell?
  30. Delete directory filled in Windows 11 and 10 comandline?
  31. Quickly delete many files recursively via the command line?
  32. Delete directory quickly administrator?
  33. Delete Windows console folder?
  34. Windows cmd promptly delete directory, powershell command delete not empty folder?
  35. Delete Windows folder with specific date?
  36. Delete directory and subdirectories quickly?
  37. Windows 11 and 10 command prompt delete folder?
  38. Powershell delete directory with subfolders or Windows 11 and 10 command prompt delete folder?
  39. Powershell delete directory and files, delete Windows command line despite protection?
  40. Delete Windows powershell commands?
  41. Dos Script to delete directories?
  42. Delete files via command prompt Windows?
  43. delete windows key windows 11 and 10 powershell?
  44. Windows command delete directories with files?
  45. Delete directory name with date from to powershell?
  46. Powershell delete empty folder and path?
  47. Force delete directory on Windows command line?
  48. Force delete Windows directory?
  49. delete directory Windows 11 and 10 with cmd?
  50. Remove-Item doesn't work in PowerShell?
  51. I would like to delete my folders and files with PowerShell or Command Prompt, who shows me exactly how to do this with PowerShell or cmd.exe?
  52. Windows delete a complete directory path, delete Windows 11 and 10 folder via powershell?
  53. Can I also delete individual folders with PowerShell if I want to delete a folder with Windows PowerShell, what do I have to enter for command?
  54. I want to delete and create folders using Windows PowerShell?
  55. Dos command delete directory completely, delete cmd without query?
  56. Delete Windows 11 and 10 directories in console?
  57. Who should I work with PowerShell folders and files?
Keywords: windows, 12, 11, 10, server, eleven, console, using, powershell, delete, complete, directories, examples, subdirectories, deleting, preface, 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
  + CoronaKO
  + MatriX.CoronaKO
  + Find.Same.Images.OK
  + 3D.Benchmark.OK
  + PhotoResizerOK
  + Office.Files.Images
  + Film.Strip.Explorer
  + WinScan2PDF
  + DontSleep
  + 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


► Recycle Bin Secure Delete via Explorer Right-click for Windows 11, 10, ...! ◄
► I don't want my Windows 11 taskbar to be centered! ◄
► Show more decimal digit in folder size in Windows all! ◄
► Executing commands from the file explorer address bars in Q-Dir! ◄


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

....