How to Delete Folders and Subfolders in PowerShell

How to Delete Folders and Subfolders in PowerShell

Getting rid of any file on Windows 10 is as easy as eating pie. However, the duration of the deletion process executed in File Explorer varies from item to item. The various factors that influence it are size, number of individual files to be deleted, file type, etc. Thus, deleting large folders containing thousands of individual files can take hours. In some cases, the estimated time displayed during deletion can even be more than a single day. Moreover, the traditional way of deleting is also slightly inefficient as you will need to empty Recycle bin to permanently remove these files from your PC. So, in this article, we will discuss how to delete folders and subfolders in Windows PowerShell quickly.

How to Delete Folders and Subfolders in PowerShell

How to Delete Folders and Subfolders in Windows PowerShell

The simplest ways of deleting a folder are listed below:

  • Select the item and press the Del key on the keyboard.
  • Right-click on the item and select Delete from the context menu that appears.

However, the files that you delete are not permanently deleted by the PC, since the files will still be present in the Recycle bin. Hence, to remove files permanently from your Windows PC,

  • Either press Shift + Delete keys together to delete the item.
  • Or, right-click Recycle bin icon on the Desktop & then, click Empty recycle bin option.

Why Delete Large Files in Windows 10?

Here are some reasons to delete large files in Windows 10:

  • The disk space on your PC might be low, so it is required to clear out space.
  • Your files or folder might have duplicated accidentally
  • Your private or sensitive files can be deleted so that no one else can access these.
  • Your files might be corrupt or full of malware due to attack by malicious programs.

Issues With Deleting Large Files and Folders

Sometimes, when you delete larger files or folders you might face annoying issues like:

  • Files can’t be deleted – This happens when you try to delete application files and folders instead of uninstalling them.
  • Very long duration of deletion – Before starting the actual deleting process, the File Explorer checks the contents of the folder & calculates the total number of files to provide an ETA. Apart from checking and calculating, Windows also analyzes the files in order to display updates on the file/folder that is being deleted at that moment. These additional processes contribute greatly to the overall delete operation period.

Must Read: What is HKEY_LOCAL_MACHINE?

Fortunately, there are a few ways to bypass these unnecessary steps and speed up the process to delete large files from Windows 10. In this article, we will walk you through various methods of doing the same.

Method 1: Delete Folders and Subfolders in Windows PowerShell

Follow the steps mentioned below to delete large folders using PowerShell app:

1. Click on Start and type powershell, then click on Run as administrator.

open Windows PowerShell as administrator from windows search bar

2. Type the following command and hit the Enter key.

Remove-Item -path C:\Users\ACER\Documents\large_folders -recurse

Note: Change the path in the above command to the folder path which you want to delete.

type the command to delete file or folder in Windows PowerShell. How to Delete Folders and Subfolders in PowerShell

Also Read: How to Delete Win Setup Files in Windows 10

Method 2: Delete Folders and Subfolders in Command Prompt

According to official Microsoft documentation, the del command deletes one or more files and the rmdir command deletes file directory. Both of these commands can also be run in the Windows Recovery Environment. Here’s how to delete folders and subfolders in Command Prompt:

1. Press Windows + Q keys to launch the search bar.

Press Windows key and Q to launch the Search bar

2. Type Command Prompt and click the Run as Administrator option in the right pane.

Type Command Prompt and click Run as Administrator option on the right pane. How to Delete Folders and Subfolders in PowerShell

3. Click Yes in the User Account Control pop-up, if prompted.

4. Type cd and the folder path you want to delete and hit Enter key.

For example, cd C:\Users\ACER\Documents\Adobe as shown below.

Note: You can copy the folder path from the File Explorer application so that there are no mistakes.

open a folder in command prompt

5. The command line will now reflect the folder path. Cross-check it once to ensure the entered path to delete the correct files. Then, type the following command and hit Enter key to execute.

del /f/q/s *.* > nul

enter command to delete the folder in command prompt. How to Delete Folders and Subfolders in PowerShell

6. Type cd . . command to go back one step in the folder path and hit Enter key.

type cd.. command in command prompt

7. Type the following command and hit Enter to delete the folder specified.

rmdir /q/s FOLDER_NAME

Change the FOLDER_NAME with the name of the folder which you want to delete.

the rmdir command to delete the folder in command prompt

This is how to delete large folders and subfolders in Command Prompt.

Also Read: How to Force Delete File in Windows 10

Method 3: Add Quick Delete Option in Context Menu

Although, we have learned how to delete folders and subfolders in Windows PowerShell or Command Prompt, the procedure needs to be repeated for every individual large folder. To ease this further, users can create a batch file of the command and then add that command to File Explorer context menu. It is the menu that appears after you right-click on a file/folder. A quick delete option will then be available for every file and folder within the Explorer for you to choose from. This is lengthy procedure, so follow it carefully.

1. Press Windows + Q keys together and type notepad. Then click Open as shown.

search notepad in windows search bar and click open. How to Delete Folders and Subfolders in PowerShell

2. Carefully copy and paste the given lines in the Notepad document, as depicted:

@ECHO OFF
ECHO Delete Folder: %CD%?
PAUSE
SET FOLDER=%CD%
CD /
DEL /F/Q/S "%FOLDER%" > NUL
RMDIR /Q/S "%FOLDER%"
EXIT

type the code in Notepad

3. Click the File option from the top left corner and choose Save As… from the menu.

click on File and select Save as option in Notepad. How to Delete Folders and Subfolders in PowerShell

4. Type quick_delete.bat as File name: and click the Save button.

Type quick delete.bat to the left of File name and click Save button.

5. Go to Folder location. Right-click quick_delete.bat file and choose Copy shown highlighted.

Right click quick delete.bat file and choose Copy from the menu. How to Delete Folders and Subfolders in PowerShell

6. Go to C:\Windows in File Explorer. Press Ctrl + V keys to paste the quick_delete.bat file here.

Note: In order to add the quick delete option, the quick_delete.bat file needs to be in a folder that has a PATH environment variable of its own. The path variable for the Windows folder is %windir%.

Go to Windows folder in File Explorer. Press Ctrl and v to paste the quick delete.bat file in that location 

7. Press Windows + R keys simultaneously to launch Run dialog box.

8. Type regedit and hit Enter to open the Registry Editor.

Note: If you are not logged in from an administrator account, you will receive a User Account Control pop-up requesting permission. Click on Yes to grant it and continue the next steps to delete folders and subfolders.

type regedit in Run dialog box

9. Go to HKEY_CLASSES_ROOT\Directory\shell as depicted below.

go to the shell folder in registry editor. How to Delete Folders and Subfolders in PowerShell

10. Right-click on shell folder. Click New> Key in the context menu. Rename this new key as Quick Delete.

right click on shell folder and click New and select Key option in Registry Editor

11. Right-click on the Quick Delete key, go to New, and choose Key from the menu, as illustrated below.

right click on Quick Delete and select New and then Key option in Registry Editor

12. Rename the new key as Command.

rename the new key as command in Quick Delete folder in Registry Editor

13. On the right pane, double-click on the (Default) file to open the Edit String window.

double click on Default and Edit String window will pop up. How to Delete Folders and Subfolders in PowerShell

14. Type cmd /c “cd %1 && quick_delete.bat” under Value Data: and click OK

enter the value data in Edit String window in Registry Editor

The quick Delete option has now been added to the Explorer context menu.

15. Close the Registry Editor application and go back to the Folder you wish to delete.

16. Right-click on the folder and choose Quick Delete from the context menu, as shown.

Close the Registry Editor application and go back to the folder you wish to delete. Right click on the folder and choose Quick Delete. How to Delete Folders and Subfolders in PowerShell

As soon as you select Quick Delete, a command prompt window will appear requesting confirmation of the action.

17. Cross-check the Folder path and the Folder name once and click any key on the keyboard to delete the folder quickly.

Note: However, if you accidentally selected the wrong folder and would like to terminate the process, press Ctrl + C. The command prompt will again ask for confirmation by displaying the message Terminate batch job (Y/N)? Press Y and then hit Enter to cancel the Quick Delete operation, as depicted below.

terminate batch job to delete folder in command prompt

Also Read: How to Delete Broken Entries in Windows Registry

Pro Tip: Table of Parameters & their Uses

Parameter Function/Use
/f Forcefully deletes read-only files
/q Enables quiet mode, you do not need to confirm for every deletion
/s Executes the command on all files in folders of the specified path
*.* Deletes all the files in that folder
nul Speeds up the process by disabling console output

Execute del /? command to learn more on the same.

Execute del To know more information on the del command

Recommended:

The above methods are the most effective methods to delete large folders in Windows 10. We hope that this guide helped you to learn how to delete folders and subfolders in PowerShell & Command Prompt. Also, if you have any queries/comments regarding this article, feel free to drop them in the comments section.

Posted by
Elon Decker

Elon is a tech writer at TechCult. He's been writing how-to guides for about 6 years now and has covered many topics. He loves to cover topics related to Windows, Android, and the latest tricks and tips.

Leave a Reply

Your email address will not be published.