Here’s how to delete a folder with subfolders and files using PowerShell and Command Prompt.
Using commands, you can remove a folder that contains files and subfolders, but you must be aware of the right tool for the job. The del command is the first tool that springs to mind when you need to remove a file or folder from Windows 10’s command terminal, but you’ll quickly learn that it only works to remove files, not folders with subfolders recursively.
If you wish to delete folders that contain content, the tool you use will depend on the console you use. If you’re using Command Prompt, the programme you want to use to delete folders recursively is called rmdir (remove directory). If you’re using PowerShell, though, Remove-Item is the cmdlet that will get the job done.
You will discover two methods in this post for swiftly deleting folders with subfolders using Command Prompt and PowerShell.
Using the Command Prompt, remove directories with subfolders
Follow these instructions to use a command to delete a folder that has subfolders:
- Launch Windows 10 Start.
- Enter “Command Prompt” into the search box, then right-click the first result and choose “Run as administrator.”
- To delete an empty folder, type the following command and hit Enter.
rmdir PATH\TO\FOLDER-NAME
- Replace PATH TO FOLDER-NAME with the folder path and folder name you want to delete in the command. This illustration deletes the folder “files”:
rmdir C:\files
- To delete the folder and all of its contents, use the following command and hit Enter:
rmdir /s PATH\TO\FOLDER-NAME
- The files, folders, and subfolders in this example are deleted:
rmdir /s C:\files
- To delete a folder with content recursively without a confirmation box, enter the command shown below and hit Enter.
rmdir /s /q PATH\TO\FOLDER-NAME
In this case, the “files” folder, its child directories, and the files themselves are deleted without requesting confirmation:
rmdir /s /q C:\files
The command will erase the directories, subfolders, and files from Windows 10 once you’ve finished the instructions.
Using PowerShell, delete directories that contain subfolders
Follow these instructions to use a PowerShell command to recursively delete an entire folder:
- Launch Start.
- Right-click the first result from your search for PowerShell and choose “Run as administrator.”
- To delete an empty folder, type the following command and hit Enter.
Remove-Item PATH\TO\FOLDER-NAME
Replace PATH TO FOLDER-NAME with the folder path and folder name you want to delete in the command. This illustration deletes the folder “files”:
Remove-Item C:\files
- To delete an empty folder, type the following command and hit Enter.
Remove-Item -Recurse -Force PATH\TO\FOLDER-NAME
This illustration deletes the folder “files”:
Remove-Item -Recurse -Force C:\files
Depending on the command you select, when you complete the steps, the command will either prompt you before deleting the folder and its contents or not.
Using the -Recurse option instructs the command to destroy the folder and all of its contents without asking for approval. Although it is not necessary, the -Force option enables the removal of unique things, such as read-only or hidden files.