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

# How To Delete a Folder Using Command Prompt

Want to delete a folder or directory using Command Prompt or PowerShell? Here is the command to delete a folder or directory in Windows OS.

To delete a folder in Windows, all you have to do is find it in the File Explorer and press the Delete key on your keyboard or right-click on it and select the “Delete” option. As soon as you do that, the file is deleted and moved to the Recycle Bin. However, what if you want to delete a folder in Command Prompt or PowerShell? For that, you have to use a particular command. Once you execute the command, the Command Prompt or PowerShell will delete the folder instantly.

In general, when using a command-line tool like Command Prompt or PowerShell, deleting a folder is different from deleting a file. It’s because the folder may contain files and sub-folders. Without deleting the data inside a folder, the command-line tool cannot delete the folder itself. For example, you can type “del filename.ext” to delete a file. But, if you try the same command with a folder, it will delete the files inside the folder, not the folder itself.

The good thing is, Windows has a specific command and flags to delete folders.  It is straightforward to understand and use.

In this quick and simple Windows How-to guide, let me share the cmd to delete the folder with you.

Before proceeding, make sure there are no important files or folders in the folder you are trying to delete.

## Command to delete folder or directory

Below is the cmd to delete a folder in Windows.

First, you need to open the Command Prompt window. To do that, open the Start menu, search for “Command Prompt,” and click on the result to open it. If the folder you delete requires admin rights, open the Command Prompt window as an admin. You can do that by right-clicking the result in the Start menu and selecting the “Run as administrator” option.

After opening the Command Prompt window, follow the below steps.

If the folder is empty, i.e., it has no files or folders inside it, use the below command.

rd "C:\path\to\folder"

To delete a folder with files and sub-folders, use the below command.

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

As soon as you execute the command, the Command Prompt will delete the folder. You will not see any confirmation message. It is normal. If you don’t see any error messages, the job is done. You can verify that in File Explorer.

Important note: If the folder is in use, the command cannot delete it. 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

If you are interested, here is a simple explanation of the command and its flags.

rd is a built-in Windows command to delete a directory or folder. You can think of rd as “remove directory.” The command structure looks as shown below. The square brackets denote optional flags that can be used with the command. If you see the second command we used above, you will see the /s and /q flags.

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

If you use the rd command with a folder path, it will delete that folder as long as it is empty.

If the folder is not empty, we have to explicitly tell the command to remove all the contents, like files and sub-folders, in the folder. For that, we use the /S flag.

/S: This flag will force the rd command to go through the folder, delete all the files & sub-folders, and then delete the folder itself.

The /Q flag stands for Quite Mode. It makes it so that you don’t see a confirmation prompt before deleting the folder. If you want to see a confirmation prompt, you can omit the /Q flag. Remember that this flag only works in conjunction with the /S flag.

That is all. It is that simple delete a folder in Command Prompt. I hope this cmd delete folder guide helps you.

If you are stuck or need some help, comment below, and I will try to help as much as possible.

Scroll to Top