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!
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 10 / 8.1 / 7. This type of deletion is often used by administrators, especially on Windows Server 2016 and 2012.
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:
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:
The directory is not empty.
C:\Windows\System32>rmdir c:\Folder1 /s
Do you want to delete "c:\Folder1" (Y/N)? j
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
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
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*
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.
make is not here!
Otherwise, quite handy deleting the directories via command line under Microsoft's Windows.
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.
Removes (deletes) a directory.
RMDIR [/S] [/Q] [drive:]path
RD [/S] [/Q] [drive:]path
Removes all directories and files in the specified directory
in addition to the directory itself. Used to remove a directory
Quiet mode, do not ask if ok to remove a directory tree with /S
You can safely use this on the following operating systems: Windows 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.) ... The most important commands for handling files / folders in Powershell!
The PowerShell commands:
a folder or file
= Show a folder or file
= Change folder or file properties
= Create a new folder or file
FAQ 33: Updated on: 30 July 2020 11:47
There are commands to control the power settings under Windows, it makes sense if you want to change them by batch file Here are a few examples, or a solution,
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
The solution is simple to disable and enable SmartScreen via CMD BATCH command and command prompt Smart Screen beim Internet Explorer deaktivieren C:\Windows\System32>REG
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
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
The command prompt on Windows allows you to view / query shared folders and current sessions / open files The solution is quite simple with the NET SHARE
Time controlled Autostart of Windows programs In new Windows OS you can use SCHTASK to start programs at a certain time Start the cmd.exe and use the command "SCHTASK" in
»» My question is not there in the FAQ
|Asked questions on this answer:|
- Powershell command delete all data in directory?
- Delete complete folder with subfolder of cmd level?
- Delete files in subdirectories windows?
- Delete Windows powershell commands?
- Delete Windows folder with specific date?
- Dos Script to delete directories?
- How do I open PowerShell and delete folders with subfolders using Windows PowerShell?
- Force delete directory on Windows command line?
- Help, can't delete a file or folder, what step by step can I use in PowerShell to delete files and folders?
- Delete folders and files with Windows command prompt?
- Who should I work with PowerShell folders and files?
- Delete Windows 10 directories in console?
- Windows cmd promptly delete directory, powershell command delete not empty folder?
- Command prompt delete directory?
- Delete Dos command with subdirectories?
- Windows 10 cmd not delete empty directory?
- Search example delete a folder or delete files and folders what parameters if a folder is not empty?
- Windows command delete directories with files?
- Powershell delete directory with subfolders or Windows 10 command prompt delete folder?
- Delete Windows console folder?
- Windows delete a complete directory path, delete Windows 10 folder via powershell?
- 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?
- Delete Windows 10 folders without asking, delete Windows directories powershell?
- I like to work with the CMD console under Windows, can I delete folders directly from there?
- Powershell delete empty folder and path?
- Quickly delete many files recursively via the command line?
- 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?
- Prompt command to delete?
- Delete Powershell directories?
- Delete files via command prompt Windows?
- Delete directory quickly administrator?
- Windows 10 command prompt delete folder?
- delete directory Windows 10 with cmd?
- Cmd delete directory contents Windows 10?
- delete windows key windows 10 powershell?
- Delete directory name with date from to powershell?
- Force delete file from Powershell?
- Delete directory and subdirectories quickly?
- 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?
- Windows cmd delete empty directories?
- Can I create and delete many folders in a few minutes using PowerShell?
- Powershell delete directory and files, delete Windows command line despite protection?
- I want to delete and create folders using Windows PowerShell?
- 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?
- Win cmd delete command without confirmation?
- Delete directory filled in Windows 10 comandline?
- Can I delete a folder using the PowerShell command?
- Force delete Windows directory?
- 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?
- How to delete multiple files using cmd or PowerShell command to remove more than one folder with Windows without checking files within a folder?
- Delete multiple files with PowerShell, if I want to delete multiple files, do I have to enter another command?
- 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?
- How do I delete files and folders using Windows PowerShell so delete all files and folders using Windows PowerShell?
- Dos command delete directory completely, delete cmd without query?
- Remove-Item doesn't work in PowerShell?
- I want everything to do with Windows?
- Which commands do I need for editing folders, PowerShell commands also CMDlets?
Keywords: windows, console, using, powershell, delete, complete, directories, with, examples, subdirectories, deleting, preface, Questions, Answers, Software