Home » How To » How To Delete a Folder Using Command Prompt

How to Delete Folders Using Command Prompt

Ever wanted to delete folders using the Command Prompt in Windows 10 or Windows 11? It’s pretty easy to do. Let’s learn how.

Deleting a folder in Windows is simple. Select the folder and press the “Delete” key on your keyboard. However, there are times when you’ll need to use the Command Prompt, such as when you can’t delete it through File Explorer or when automating tasks with a script. Then, you can use a special built-in command to quickly delete any folder, even folders containing files or subfolders.

In this tutorial, I will show you the simple way to delete folders in Windows 10 and Windows 11 using the Command Prompt command. Let’s get started.

Before You Begin

  • Some folders require administrator rights to delete. If you encounter an “Access Denied” or similar error, right-click on the Command Prompt or PowerShell icon and select “Run as administrator.
  • These commands permanently delete folders and their contents. Before proceeding, ensure you have backed up any important data in them.
  • The steps shown below will work in Windows 11 and Windows 10.

Delete Folders Using Command Prompt

  1. Press the “Windows key” to open the Start menu.
  2. Search and open “Command Prompt“.
  3. Run the following command while replacing the dummy path with the actual path of the folder.
    rd /s /q "C:\path\to\folder"
  4. With that, you’ve deleted the folder via the command line.

Good to know: How to force delete files in Command Prompt

Detailed Steps (With Screenshots)

First, open the Command Prompt tool. To do that, open the Start menu by pressing the “Windows key” on your keyboard, search for “Command Prompt“, and click “Open“.

open command prompt

Once the Command Prompt window opens, run the following command while replacing the dummy path with the actual path of the folder you want to delete.

rd /s /q "C:\path\to\folder"

For example, I want to delete a folder on my desktop. So, I replaced the dummy path with that specific path. You can see it in the below screenshot.

command to delete folder with files and sub-folders

As soon as you execute the command, the Command Prompt will delete the folder. You will not see any confirmation message. It is normal. You can verify if the folder is deleted using File Explorer.

Note: If the folder is in use, the folder cannot be deleted. In that case, you have to make sure no program is using the folder or a file or sub-folder in the target folder before running the command.

Command Explanation

Want to know how the command works? Here’s a simple breakdown of rd and its flags.

rd is a built-in Windows command for deleting directories (or folders). Think of rd as short for “remove directory.” The command structure is:

rd [<drive>:]<path> [/s [/q]]

If you use rd with just a folder path, it will only delete the folder if it’s empty.

But what if the folder has files or subfolders inside? Then you need to tell rd to remove everything inside first. That’s where the /s flag comes in.

/s: This flag tells rd to go through the folder, delete all files and subfolders, and then delete the folder itself.

The /q flag stands for “Quiet Mode.” It prevents a confirmation prompt from appearing before deleting the folder. If you want to see the confirmation prompt, just leave out the /q flag. Keep in mind that /q only works when you also use /s.

Wrapping Up — Deleting Directories from Command Line

Deleting a folder (or directory) from the command line is straightforward. Just use the rd command with the folder’s path. Remember: If the folder requires administrator rights, open Command Prompt or PowerShell as administrator. Also, if the folder is in use, close it before attempting to delete it.

If you have any questions or need help, comment below. I’ll be happy to help.

Leave a Comment

Your email address will not be published. Required fields are marked *